Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » Java与OOP初步  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 java.lang.NullPointerException
linqiuppp





发贴: 8
积分: 0
于 2005-10-25 00:46 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
通过编译,但运行时发生这个java.lang.NullPointerException错误!Question



JAVA学习日子分享
作者 Re:java.lang.NullPointerException [Re:linqiuppp]
linqiuppp





发贴: 8
积分: 0
于 2005-10-25 00:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
哪位大吓愿意指点小弟一下!下面是源程序。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.geom.*;

public class BoundThread
{
public static void main(String []args)
{
BoundFrame frame=new BoundFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();  
}  
}

class BoundFrame extends JFrame
{
public BoundFrame()
{
setTitle("BoundThread");
setSize(500,400);
panel=new BoundPanel();
Container contentPane=getContentPane();
contentPane.add(panel,BorderLayout.CENTER);
JButton start=new JButton("Start");
JButton close=new JButton("Close");
start.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
Ball ball=new Ball(panel);
panel.add(ball);
BallThread thread=new BallThread(ball);
thread.start();
  
}  
});  

close.addActionListener(new ActionListener()
{
  public void actionPerformed(ActionEvent event)
   {
     System.exit(0);
   }
     
});
  JPanel buttonPanel=new JPanel();
  buttonPanel.add(start);
  buttonPanel.add(close);
  contentPane.add(buttonPanel,BorderLayout.SOUTH);
}   

private BoundPanel panel;
}

class BallThread extends Thread
{
public BallThread(Ball aball)
{
  ball=aball;
  
}  
public void run()
{
try{
  
  for(int i=0;i<10000;i++)
   {
      ball.move();
      sleep(5);
   }
   }
  catch( InterruptedException e){}  
}

private Ball ball;
}

class BoundPanel extends JPanel
{
public void add(Ball aball)
{
balls.add(aball);  
}

public void paintComponent(Graphics g)
{
super.paintComponentPresent;

Graphics2D g2=(Graphics2D)g;

for(int i=0;i<balls.size();i++)
{
Ball ball=(Ball)balls.getLight Bulb;
g2.fill(new Ellipse2D.Double(ball.x,ball.y,ball.Scale,ball.Scale));  
}  
}  
private ArrayList balls;
}

class Ball
{
public Ball(Component apanel)
{
panel=(BoundPanel)apanel;
  
}  
public void move()
{
x=x+dx;
y=y+dy;
if(x<0){x=0;dx=-dx;}
if(y<0){y=0;dy=-dy;}
if(x+Scale>panel.getWidth()) {x=panel.getWidth()-Scale;dx=-dx;}
if(y+Scale>panel.getHeight()) {y=panel.getHeight()-Scale;dy=-dy;}
panel.repaint();  
}
private BoundPanel panel;
private int dx=2;
private int dy=2;
public int x=0;
public int y=0;
public int Scale=10;

}




基于WEB的J2EE报表解决方案集锦
作者 Re:java.lang.NullPointerException [Re:linqiuppp]
linqiuppp





发贴: 8
积分: 0
于 2005-10-25 15:11 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我知道错哪了,忘了初始化ArrayList.
谢谢大家!




如何用JTable设置表头多行
作者 Re:java.lang.NullPointerException [Re:linqiuppp]
andony756





发贴: 21
积分: 1
于 2005-11-27 14:33 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
大家好!
我想请问一下
我的程序和数据库都没问题的情况下
编译时总出现java.lang.NullPointerException
是怎么回事
我电脑的操作系统home版的xp sp2的
数据库是SQL SERVER 2000的
是不是不能和数据库连接
也许是xp自带防火墙的问题
请问如何解决




从Coding Fan到真正的技术专家
作者 Re:java.lang.NullPointerException [Re:andony756]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2005-11-27 19:15 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
andony756 wrote:
我的程序和数据库都没问题的情况下
编译时总出现java.lang.NullPointerException
是怎么回事
我电脑的操作系统home版的xp sp2的
数据库是SQL SERVER 2000的
是不是不能和数据库连接
也许是xp自带防火墙的问题
请问如何解决

Show us the code.

Check on our Database board.




Windows环境下的tomcat + apache配置(绝对实践操作版)
作者 Re:java.lang.NullPointerException [Re:linqiuppp]
youyigong





发贴: 2
积分: 0
于 2005-11-28 13:56 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这个问题很简单,因为你的环境变量没设好,重新设好吧!

你把jdk放在哪个盘下 path=盘:\j2sdk1.4.2_04\bin
classpath=.;盘:\j2sdk1.4.2_04\lib\tools.jar;盘:\j2sdk1.4.2_04\lib\dt.jar
就行了


youyigong edited on 2005-11-28 14:01


有了Swing为什么还要SWT?
作者 Re:java.lang.NullPointerException [Re:linqiuppp]
andony756





发贴: 21
积分: 1
于 2005-11-28 21:21 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
谢谢大家的帮助
程序代码请见附件
package com.ctc.forum.db;

import java.sql.*;
import com.ctc.forum.util.PropertyFileManager;

public class DBConnection {
public DBConnection() {
}

public static Connection getConnection() {
Connection conn = null;
try {
PropertyFileManager pm = new PropertyFileManager("config");
String driver = pm.getValue("driver");
Class.forName(driver).
newInstance();
String url = pm.getValue("url");
String user = pm.getValue("username");
String password = pm.getValue("password");
conn = DriverManager.getConnection(url, user, password);
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
}
return conn;
}

public static void main(String[] args) {
Connection conn = DBConnection.getConnection();
if (conn != null) {
System.out.print("ok");
}
}
}


770KB attachment's removed.
use the one on http://www.cjsdn.net/post/view?bid=10&id=164214


why edited on 2005-11-30 17:48


我有一点感想和初学者们同享(原创)
作者 Re:java.lang.NullPointerException [Re:andony756]
ntshenwh





发贴: 40
积分: 0
于 2005-11-28 22:09 user profilesend a private message to usersend email to ntshenwhsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
hi, by your attachment, i test it, it is ok,I just change url to url=jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=pubs


勿在浮砂筑高台

[转帖]面向对象的思维方法
作者 Re:java.lang.NullPointerException [Re:linqiuppp]
andony756





发贴: 21
积分: 1
于 2005-11-28 22:32 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ntshenwh:
first,thank you for your help
but 在我的电脑上还是出现上面的错误提示
我电脑的操作系统home版的xp sp2的
数据库是SQL SERVER 2000的
现在装sql2ksp4
安全中心也关了
还是一样的错误
请再帮看看是哪的问题
谢谢




从Coding Fan到真正的技术专家
作者 Re:java.lang.NullPointerException [Re:andony756]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2005-11-29 18:22 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
andony756 wrote:
ntshenwh:
first,thank you for your help
but 在我的电脑上还是出现上面的错误提示
我电脑的操作系统home版的xp sp2的
数据库是SQL SERVER 2000的
现在装sql2ksp4
安全中心也关了
还是一样的错误
请再帮看看是哪的问题
谢谢

Have you checked on our Database board?
You may post your question on one of those existing topics.

在我的电脑上还是出现上面的错误提示??
Did you really mean "编译时总出现java.lang.NullPointerException"?
If you got the error while 编译时, how could you say "我的程序和数据库都没问题"
Are you sure ?Question
It's impossible.




Hibernate开发指南
作者 Re:java.lang.NullPointerException [Re:linqiuppp]
andony756





发贴: 21
积分: 1
于 2005-11-29 20:37 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
呵呵
为什么我会说我的程序和数据库是没问题的
那是因为完全一样的程序和设置
在我原来的电脑上是能运行的
而现在我只要是与数据库有关的程序都是同样的错误提示
我只是拿以前能运行的例子做测试
请帮我找出原因所在
谢谢




Hibernate开发指南
作者 Re:java.lang.NullPointerException [Re:andony756]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2005-11-30 17:50 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
andony756 wrote:
呵呵
为什么我会说我的程序和数据库是没问题的
那是因为完全一样的程序和设置
在我原来的电脑上是能运行的
而现在我只要是与数据库有关的程序都是同样的错误提示
我只是拿以前能运行的例子做测试
请帮我找出原因所在
谢谢

Okay, now I know, it's jsp.

770KB attachment's removed. (Please don't triple-post your question and attachmentDead)
Please continue on http://www.cjsdn.net/post/view?bid=10&id=164214




Hibernate开发指南
作者 Re:java.lang.NullPointerException [Re:linqiuppp]
wangyabing





发贴: 18
积分: 0
于 2005-12-29 16:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
I can not run it ,I use JCreator ,please tell me



一个程序员的奋斗历程
作者 Re:java.lang.NullPointerException [Re:wangyabing]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2005-12-29 20:46 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
wangyabing wrote:
I can not run it ,I use JCreator ,please tell me

What is the "it" that you couldn't run?




JBuilder使用技巧

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923