本人现在调试一个程序,在windows中很正常!但是移植到Linux中就不行了!问题是
这个方法;
final String listcatPath = inputTextField.getText();
然后
if (!listcatPath.equals(""))在linux中就开始报错了.
原因我知道,是因为listcatPath一直是Null.然后报错 exception是 NullPointerException, 但是在Windows中是"",所以一切正常!
很奇怪!
大家有这方面经验的很帮忙啊.我的头很着急,我想尽快把这个问题解决掉.
这个方法;
final String listcatPath = inputTextField.getText();
然后
if (!listcatPath.equals(""))在linux中就开始报错了.
原因我知道,是因为listcatPath一直是Null.然后报错 exception是 NullPointerException, 但是在Windows中是"",所以一切正常!
很奇怪!
大家有这方面经验的很帮忙啊.我的头很着急,我想尽快把这个问题解决掉.
}不就可以了?
if (listcatPath != null && !listcatPath.equals(""))平台之间的差异有时候很微妙的,getText()方法的定义规范里并没有要求不能返回null,所以你自己的程序必须学会去兼容它。
这就是为什么!
public String getText()
Returns the text contained in this TextComponent. If the underlying document is null, will give a NullPointerException. Note that text is not a bound property, so no PropertyChangeEvent is fired when it changes. To listen for changes to the text, use DocumentListener.
Returns:
the text
Throws:
NullPointerException - if the document is null
See Also:
setText(java.lang.String)
这段看不懂.请指教!
public String getText()
Returns the text contained in this TextComponent. If the underlying document is null, will give a NullPointerException. Note that text is not a bound property, so no PropertyChangeEvent is fired when it changes. To listen for changes to the text, use DocumentListener.
Returns:
the text
Throws:
NullPointerException - if the document is null
See Also:
setText(java.lang.String)
这段看不懂.请指教!
public String getText()返回此 TextComponent 中包含的文本。如果底层文档为 null,则将给出 NullPointerException。注意,文本不是绑定属性,所以更改时不触发 PropertyChangeEvent。要侦听文本的更改,请使用 DocumentListener。 返回:
文本
抛出:
NullPointerException - 如果文档为 null
另请参见:
setText(java.lang.String)--------------------------------------------------------------------------------
看不懂就找个中文版的
final String Path1 =inputTextField.getText();
final String Path2 = inputTextField2.getText();
final String dd=Path2;
final String sss="ABC";
System.out.println(Path1); .....最后结果会是实际的一个路径
System.out.println(Path2); .....最后结果会是实际的一个路径
System.out.println(dd); .....与Path2所指的路径一样
System.out.println(sss); .....显示为"ABC"
MW=new ModalWorker(MainWindow.instance)
{
public void modalRun()
{ System.out.println(Path1); ......结果是Null
System.out.println(Path2); ......结果是Null
System.out.println(dd); ......结果是Null
System.out.println(sss); ......结果是"ABC"
....
s = (s == null)?"":s;if(s.equals("")) {
//......
}
谢谢大家!
对了,本人没有帮助日本人做事,也根本不懂什么事日语.只是想问大家这个问题.谢谢.