Java初学者CSDN第4问!

nisus_lee 2005-10-28 04:39:06
class Link
{
public long dData;
public Link next;

public Link(long dd)
{
dData=dd;
}

public void displayLink()
{
System.out.print(dData+" ");
}
}

class LinkList
{
private Link first;

public LinkList()
{
first=null;
}

public boolean isEmpty()
{
return(first==null);
}

public void insertFirst(long dd)
{
Link newLink=new Link(dd);
newLink.next=first;
first=newLink;
}

public long deleteFirst()
{
Link temp=first;
first=first.next;
return temp.dData;
}

public void displayList()
{
Link current=first;
while(current!=null)
{
current.displayLink();
current=current.next;
}
System.out.println("");
}
}

class LinkStack
{
private LinkList theList;

public void push(long j)
{
theList.insertFirst(j);
}

public long pop()
{
return theList.deleteFirst();
}

public boolean isEmpty()
{
return (theList.isEmpty());
}

public void displayStack()
{
System.out.print("Stack(top-->bottom):");
theList.displayList();
}
}

class LinkStackApp
{
public static void main(String[] args)
{
LinkStack theStack=new LinkStack();

theStack.push(20);
theStack.push(40);

theStack.displayStack();

theStack.push(60);
theStack.push(80);

theStack.displayStack();

theStack.pop();
theStack.pop();

theStack.displayStack();
}
}

编译通过,可是无法运行,显视的是:
Exception in thread "main" java.lang.NullPointerExcep
at LinkStack.push(LinkStackApp.java:66)
at LinkStackApp.main(LinkStackApp.java:92)
望各位指点下 !
...全文
139 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
superslash 2005-10-28
  • 打赏
  • 举报
回复
wo dao
nisus_lee 2005-10-28
  • 打赏
  • 举报
回复
问题解决 ..谢谢 ……
yanxiazhiqiu 2005-10-28
  • 打赏
  • 举报
回复
你就是问题终结者 ,求倒!
zhaoguoqingluntan 2005-10-28
  • 打赏
  • 举报
回复
up

ianok 2005-10-28
  • 打赏
  • 举报
回复
up
classjava 2005-10-28
  • 打赏
  • 举报
回复
class LinkStack
{
private LinkList theList;//这个改成private LinkList theList=new LinkList();

public void push(long j)
{
theList.insertFirst(j);
}

public long pop()
{
return theList.deleteFirst();
}

public boolean isEmpty()
{
return (theList.isEmpty());
}

public void displayStack()
{
System.out.print("Stack(top-->bottom):");
theList.displayList();
}
}
这是一个实际使用中的项目,可访 http://cdbke.cuit.edu.cn 可查看效果及功能,后台需要登录后才能使用(出于安全性考虑这里就不给大家介绍了,另外还有一个struts1版本的,如有需要可以与我联系)。 此项目整合了目前主流和最前源的web开发技术:采用ehcache实现二级缓存(包含查询缓存);用sf4j及logback(log4j的升级版)记录日志;proxool(据说是dbcp和c3p0三者中最优秀的)做连接池;使用jquery的ajax实现仿google人名自动补全;头像上传剪切压缩处理。 包含有完整的jar包和源代码,可以直接下载编译部署和运行,这是专门为我们实验室定制开发的。虽然后台逻辑并不复杂,但已经包含了架构基于s2sh技术型系统的全部基础部分:如分页,缓存,文件上传,连接池等。很适合学习使用,希望对初学JavaEE WEB开的人有所帮助。 这个资源在去年发布了第一版,已经有很多朋友下了觉得对他们有帮助,所以我才再发了一个第二版,希望对有需要的朋友有所帮助。本版本全面更新了jar包,全部使用了当前最新版本的jar包,struct2.1.8 spring3 hibernate3.5,全面使用注解取代xm的l配置。 另外增加了一个ant构建脚本,支持使用hudson完成每日构建,持续集成,自动测试,代码规范检查,代码审查等功能(与此相关的jar包由于上传文件大小限制未导入) 本系统一直在使用中,所以还会不段更新,之后我打算再做一个基于javaee6的实现,给需要想学习ejb3.1等技术的朋友一个参考实现 集成测试相关jar包和更新构建脚本下载:http://download.csdn.net/source/2427972

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧