import java.text.DateFormat;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
public class myTime extends JFrame
{
private JTextArea timeOutput;
private DateFormat currentTime;
public myTime()
{
super( "Clock" );
Container mycontainer = getContentPane();
mycontainer.setLayout( new FlowLayout() );
timeOutput = new JTextArea();
mycontainer.add( timeOutput );
//currentTime = new DateFormat();
currentTime.getTimeInstance();
String output = "";
output += currentTime.toString();/////////此处异常
timeOutput.setText( output );
JOptionPane.showMessageDialog( null, output, "Time", JOptionPane.INFORMATION_MESSAGE );
setSize( 300, 300 );
setVisible( true );
}
public static void main( String args[] )
{
myTime mytime = new myTime();//////////此处异常
mytime.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
大家帮帮忙,可直接联系yanmin0614@163.com,谢谢!
----------------解决方案--------------------------------------------------------
output没有初始化,应该给他初始化的
----------------解决方案--------------------------------------------------------
空引用异常 你有SUPER()却没传递一个参数改 成 public myTime(String s) super( s );
myTime mytime = new myTime("Clock");//////////
----------------解决方案--------------------------------------------------------
谢谢,谢谢二位仁兄.谢谢OPPLE,一语道破,茅塞顿开,谢谢啦.
----------------解决方案--------------------------------------------------------
import java.util.Date;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JOptionPane;
class Window extends JFrame
{
private JTextArea timeOutput;
private Date currentTime;
public Window(String s)
{
super(s);
Container mycontainer = getContentPane();
mycontainer.setLayout( new FlowLayout() );
timeOutput = new JTextArea();
mycontainer.add( timeOutput );
currentTime = new Date();
String output =null;
output=currentTime.toString();/////////此处异常
timeOutput.setText( output );
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JOptionPane.showMessageDialog( null, output, "Time", JOptionPane.INFORMATION_MESSAGE );
setSize( 300, 300 );
setVisible( true );
}
}
public class test
{
public static void main( String args[] )
{
Window win= new Window("clock");//////////此处异常
}
}
你要现实的是这样的吗?
----------------解决方案--------------------------------------------------------
空指针...
----------------解决方案--------------------------------------------------------