| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 416 人关注过本帖
标题:java程序问题求助??
只看楼主 加入收藏
魔鬼之子
Rank: 1
来 自:地狱之都
等 级:新手上路
帖 子:100
专家分:0
注 册:2007-9-22
结帖率:71.43%
收藏
 问题点数:0 回复次数:2 
java程序问题求助??
这是我编的一个java链表,但是在调试时总是出现以下提示:
import java.io.*;
import java.lang.*;
public class Lisk1{
private Node Head=null;
private Node Tail=null;
private Node Pointer;
private int Length=0;
void insert(Lisk1 a,Node e)
{
a.Length++;
if(a.Length==1)
{
a.Head=e;
a.Tail=a.Head;
a.Pointer=a.Head.next;
}
else
{
a.Tail.next=e;
a.Tail=e;
a.Pointer=e.next;
}
}
void output(Lisk1 a)
{
a.Pointer=a.Head;
for(int i=1;i<=a.Length;i++){
System.out.print(Pointer.data+" ");
a.Pointer=a.Pointer.next;
if(a.Pointer==null)
throw new java.lang.NullPointerException();
}
}
void delete(Lisk1 a,int j){
int i=1;
a.Pointer=a.Head;
if(j==1){
System.out.println("The chracter is"+" "+a.Pointer.data);
a.Head=a.Pointer.next;
}
else
{
while(i!=j-1)
{
a.Pointer=a.Pointer.next;
i++;
}
System.out.println("The chracter is"+" "+a.Pointer.next.data);
if(j==10)
a.Tail=a.Pointer;
a.Pointer=a.Pointer.next.next;

}
}
public static void main(String[] args){
int i;
int j=2;
Lisk1 a=new Lisk1();
for(i=0;i<10;i++){
Node e=new Node(new Integer(i));
a.insert(a,e);
}
System.out.println("Please output the characters of link:");
a.output(a);
System.out.println("Please delete the index");
a.delete(a,j);
}
}
class Node{
Object data;
Node next;
public Node(Object d){
data=d;
next=null;
}
}
提示:Exception in thread "main"java.lang.NullPointerException at Lisk1.output<Lisk1.java:31>
at Lisk1.main<Lisk1.java:64>

望各位人兄帮帮忙!!!!
搜索更多相关主题的帖子: java 
2007-09-25 17:20
cwjieNO1
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-8-20
收藏
得分:0 

我用 Eclipse 编译是这样的,你这个异常 NullPointerException(); 没有定义,只是抛出,没有catch.
我定义了一下,输出这样的结果:
Please output the characters of link:
0 1 2 3 4 5 6 7 8 9 please delete the index
The chracter is 1

/* 修改的地方 */
void output(Lisk1 a)
{
try{
a.Pointer=a.Head;
for(int i=1;i<=a.Length;i++)
{
System.out.print(Pointer.data+" ");
a.Pointer=a.Pointer.next;
if(a.Pointer==null)
throw new java.lang.NullPointerException();
}
}catch(NullPointerException e ) {}

}



2007-09-26 15:32
tellme123
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-9-8
收藏
得分:0 

呵呵.太厉害了啊

2007-09-27 16:40
快速回复:java程序问题求助??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021452 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved