【发布时间】:2014-04-01 17:49:20
【问题描述】:
我收到了一个NullPointerException,其中包含以下 Java 代码:
static String s[],t[],temp;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
s[0]=jTextField2.getText();
jTextField3.setText("The input string is: "+s[0]);
temp=jTextField1.getText();
t=temp.split(" ");
jTextField3.setText("The input string is: "+t[0]);
}
此代码一直给我java.lang.NullPointerException。我的代码有什么问题???
我也试过这种方式:
static String s[],t[],temp;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
temp=jTextField2.getText();
s[0]=temp;
jTextField3.setText("The input string is: "+s[0]);
temp=jTextField1.getText();
//t=temp.split(" ");
//jTextField3.setText("The input string is: "+t[0]);
}
而且jTextField3.setText("The input string is: "+t); 也不适用于声明为静态字符串 t 的 t。在文本字段中,它再次显示了一些异常。
【问题讨论】:
标签: java string forms swing nullpointerexception