你有一个变量是Null,设断点好好找,这种错误不难找的
解决方案 »
- JDBC for MySQL设置问题,加入到classpath中仍然不行。用IDE导入能正常执行
- 求助,List myList=new ArrayList()在主类中好用但在其他类中不好用
- arraylist 匹配
- tomcat中修改了配置文件,必需重新启动tomcat才能生效?
- 多次从控制台接参流该在什么时候关闭
- 请问java有没有存储基本类型的容器?
- 各位大虾,请帮帮忙,关于REPLACE函数的问题
- http://expert.csdn.net/Expert/TopicView1.asp?id=2857896
- 监控一个运行着的程序,里面有个java对象,如何实时查看该对象的内存变化情况
- 我们公司要买软件,谁能提供这方面的信息?
- java 的基础问题
- 大家都是怎么学java的。
//Aframe.javaimport java.awt.*;
import java.awt.event.*;
public class Aframe extends Frame {
Button b;
Label look1;
TextField t1;
Doo doo; public Aframe() {
b = new Button("Add");
doo = new Doo(this);
look1 = new Label("Look1");
t1 = new TextField();
doo = new Doo(this);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doo.join();
doo.getnum();
}
});
this.setLayout(new GridLayout(5, 5));
this.add(b);
this.add(look1);
this.add(t1);
this.addWindowListener
(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}class Doo { Aframe e;
int n;
double num[] = new double[100]; public Doo(Aframe e) {
n = -1;
this.e = e;//这里是关键!!!
} public void join() {
n++;
num[n] = Double.parseDouble(e.t1.getText());
} public void getnum() {
e.look1.setText(String.valueOf(num[n]));
}
}//A.javaimport java.awt.*;
import java.awt.event.*;
import java.util.*;public class A { public static void main(String[] args) {
// Create application frame. Aframe frame = new Aframe();
frame.setSize(200, 150); // Show frame
frame.setVisible(true);
}
}你的关键错误在于:
e=e;//倒底是怎么回事?知道this怎么用吗?改成this.e=e;就没问题了。其它的原则性错误我就不想多说了,JAVA书上要比我说得好多了。不懂可以问。
问问题简化出来的,有几个地方忘了修改,不好意思啊!仔细修改了一遍已经可以正常运行了,不过我还有几个地方想请教你
就是在下面的Doo类中能不能不做AFrame的拷贝,就是有e的地方直接
用frame(frame在A.java中定义),不过这样编译通不过或者有什么办法能不拷贝也正常(比如说怎么加个包什么的,我不太懂)还有,你说的那个编译环境我怎么没有听说过啊,你是做什么的?最后感谢你能认真看完了我的问题并做了这么好的回答!//AFrame.javaimport java.awt.*;
import java.awt.event.*;
import java.util.*;
public class AFrame extends Frame {
Button b;
Label look1;
TextField t1;
Doo doo;
BListener bListener;
public AFrame() {
b=new Button("Add");
doo=new Doo(this);
look1=new Label("Look1");
t1=new TextField();
bListener=new BListener();
b.addActionListener(bListener);
this.setSize(200,150);
this.setLayout(new GridLayout(5,5));
this.add(b);
this.add(look1);
this.add(t1);
this.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
AFrame.this.windowClosed();
}
}
);
}
public class Doo
{
AFrame e;
int n;
double num[]=new double[100];
public Doo(AFrame e)
{
n=-1;
this.e=e;
}
public void join()
{
n++;
num[n]=Double.parseDouble(e.t1.getText()); //-----------------
}
public void getnum()
{
e.look1.setText(String.valueOf(num[n]));//-----------------------------
}
}
public class BListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
doo.join();
doo.getnum();
}
}
protected void windowClosed() {
System.exit(0);
}
}//A.java import java.awt.*;
import java.awt.event.*;
import java.util.*;public class A {
public static void main(String[] args) {
// Create application frame.
AFrame frame = new AFrame();
// Show frame
frame.setVisible(true);
}
}
http://www.jetbrains.com/idea/index.html