Topic: java.lang.NullPointerException |
Print this page |
1.java.lang.NullPointerException | Copy to clipboard |
Posted by: linqiuppp Posted on: 2005-10-25 00:46 通过编译,但运行时发生这个java.lang.NullPointerException错误! |
2.Re:java.lang.NullPointerException [Re: linqiuppp] | Copy to clipboard |
Posted by: linqiuppp Posted on: 2005-10-25 00:48 哪位大吓愿意指点小弟一下!下面是源程序。 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.paintComponent; Graphics2D g2=(Graphics2D)g; for(int i=0;i<balls.size();i++) { Ball ball=(Ball)balls.get; 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; } |
3.Re:java.lang.NullPointerException [Re: linqiuppp] | Copy to clipboard |
Posted by: linqiuppp Posted on: 2005-10-25 15:11 我知道错哪了,忘了初始化ArrayList. 谢谢大家! |
4.Re:java.lang.NullPointerException [Re: linqiuppp] | Copy to clipboard |
Posted by: andony756 Posted on: 2005-11-27 14:33 大家好! 我想请问一下 我的程序和数据库都没问题的情况下 编译时总出现java.lang.NullPointerException 是怎么回事 我电脑的操作系统home版的xp sp2的 数据库是SQL SERVER 2000的 是不是不能和数据库连接 也许是xp自带防火墙的问题 请问如何解决 |
5.Re:java.lang.NullPointerException [Re: andony756] | Copy to clipboard |
Posted by: why Posted on: 2005-11-27 19:15 andony756 wrote: Show us the code. Check on our Database board. |
6.Re:java.lang.NullPointerException [Re: linqiuppp] | Copy to clipboard |
Posted by: youyigong Posted on: 2005-11-28 13:56 这个问题很简单,因为你的环境变量没设好,重新设好吧! 你把jdk放在哪个盘下 path=盘:\j2sdk1.4.2_04\bin classpath=.;盘:\j2sdk1.4.2_04\lib\tools.jar;盘:\j2sdk1.4.2_04\lib\dt.jar 就行了 |
7.Re:java.lang.NullPointerException [Re: linqiuppp] | Copy to clipboard |
Posted by: andony756 Posted on: 2005-11-28 21:21 谢谢大家的帮助 程序代码请见附件 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 |
8.Re:java.lang.NullPointerException [Re: andony756] | Copy to clipboard |
Posted by: ntshenwh Posted on: 2005-11-28 22:09 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 |
9.Re:java.lang.NullPointerException [Re: linqiuppp] | Copy to clipboard |
Posted by: andony756 Posted on: 2005-11-28 22:32 ntshenwh: first,thank you for your help but 在我的电脑上还是出现上面的错误提示 我电脑的操作系统home版的xp sp2的 数据库是SQL SERVER 2000的 现在装sql2ksp4 安全中心也关了 还是一样的错误 请再帮看看是哪的问题 谢谢 |
10.Re:java.lang.NullPointerException [Re: andony756] | Copy to clipboard |
Posted by: why Posted on: 2005-11-29 18:22 andony756 wrote: 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 ? It's impossible. |
11.Re:java.lang.NullPointerException [Re: linqiuppp] | Copy to clipboard |
Posted by: andony756 Posted on: 2005-11-29 20:37 呵呵 为什么我会说我的程序和数据库是没问题的 那是因为完全一样的程序和设置 在我原来的电脑上是能运行的 而现在我只要是与数据库有关的程序都是同样的错误提示 我只是拿以前能运行的例子做测试 请帮我找出原因所在 谢谢 |
12.Re:java.lang.NullPointerException [Re: andony756] | Copy to clipboard |
Posted by: why Posted on: 2005-11-30 17:50 andony756 wrote: Okay, now I know, it's jsp. 770KB attachment's removed. (Please don't triple-post your question and attachment) Please continue on http://www.cjsdn.net/post/view?bid=10&id=164214 |
13.Re:java.lang.NullPointerException [Re: linqiuppp] | Copy to clipboard |
Posted by: wangyabing Posted on: 2005-12-29 16:22 I can not run it ,I use JCreator ,please tell me |
14.Re:java.lang.NullPointerException [Re: wangyabing] | Copy to clipboard |
Posted by: why Posted on: 2005-12-29 20:46 wangyabing wrote: What is the "it" that you couldn't run? |
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 |