import java.lang.*;
import java.awt.*;
public class j013 extends Frame
{
Label L1;
TextField T1;
Button B1;
Button B2;
public j013()
{
this.setLayout(null);
L1=new Label("输入你的代号:");
L1.setBounds(40,50,80,25);
this.add(T1);
B1=new Button("Button1");
B1.setBounds(25,90,90,25);
this.add(B2);
this.setBackground(Color.yellow);
this.setBounds(0,0,250,220);
this.setTitle("this is Frame");
this.setVisible(true);
}
public static void main(String para[])
{
new j013();
}
}这是我摘抄的一段代码,编译没有问题,但运行时出现了
java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:621)
at java.awt.Container.add(Container.java:307)
at j013.<init>(j013.java:15)
at j013.main(j013.java:27)
Exception in thread "main"
不知是怎么回事,请高手指点.package je3.basics;
public class Factorial2
{
long obj1=100;
Factorial2 obj2=new Factorial2();
public static long Factorial(long x)
{
if(x<0)
throw new IllegalArgumentException("x must be >=0");
if(x<=1) return 1;
else return x*factorial(x-1);
}
System.out.println(obj2.Factorial(obj2.obj1));
}这是我自己设计的一个阶乘代码,总是有一个错误编译不过去,不知为什么?请高手指点一二.
Factorial2.java:15: <identifier> expected
System.out.println(obj2.Factorial(obj2.obj1));
^
1 error
这是错误显示.
import java.awt.*;
public class j013 extends Frame
{
Label L1;
TextField T1;
Button B1;
Button B2;
public j013()
{
this.setLayout(null);
L1=new Label("输入你的代号:");
L1.setBounds(40,50,80,25);
this.add(T1);
B1=new Button("Button1");
B1.setBounds(25,90,90,25);
this.add(B2);
this.setBackground(Color.yellow);
this.setBounds(0,0,250,220);
this.setTitle("this is Frame");
this.setVisible(true);
}
public static void main(String para[])
{
new j013();
}
}这是我摘抄的一段代码,编译没有问题,但运行时出现了
java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:621)
at java.awt.Container.add(Container.java:307)
at j013.<init>(j013.java:15)
at j013.main(j013.java:27)
Exception in thread "main"
不知是怎么回事,请高手指点.package je3.basics;
public class Factorial2
{
long obj1=100;
Factorial2 obj2=new Factorial2();
public static long Factorial(long x)
{
if(x<0)
throw new IllegalArgumentException("x must be >=0");
if(x<=1) return 1;
else return x*factorial(x-1);
}
System.out.println(obj2.Factorial(obj2.obj1));
}这是我自己设计的一个阶乘代码,总是有一个错误编译不过去,不知为什么?请高手指点一二.
Factorial2.java:15: <identifier> expected
System.out.println(obj2.Factorial(obj2.obj1));
^
1 error
这是错误显示.
解决方案 »
- 关于输入5句话然后将它逆序输出问题~~~
- 求这样字符串的怎样做替换操作
- 崩溃啦。。。救命啊。。。关于Image中DrawString
- [Fatal Error] :-1:-1: Premature end of file.!!!XML文件的读写
- 急求数据库问题,毕业设计关键部分之一。
- 如何得到服务已经运行了多少时间?
- 大家发过来了帖子,我都试过了,还是有错误呀,怎么办呀!
- 问题在哪里?
- 令人头痛的问题:如何用getString()为空的方法判断数据库表中的字段已全部遍历
- 我的JDK和jre是怎么回事呀,求各位兄弟帮帮忙
- Pattern p = Pattern.compile("^\w+$");为什么报错Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
- 哪位大哥有查询手机归属地的数据库?????
<table bodle=1>
<tr><td>class Factorial2
{
long obj1=4; public static long Factorial(long x)
{
if(x <0)
throw new IllegalArgumentException("x must be > =0");
if(x>=1)
return x*Factorial(x-1);
else return 1;
}
public static void main(String[] args)
{
Factorial2 obj2=new Factorial2();
System.out.println(Factorial2.Factorial(obj2.obj1));
}
}
</td></tr>
</table>
分配空间
T1=new TextField();