本人现在调试一个程序,在windows中很正常!但是移植到Linux中就不行了!问题是
这个方法;
final String listcatPath = inputTextField.getText();
然后
if (!listcatPath.equals(""))在linux中就开始报错了.
原因我知道,是因为listcatPath一直是Null.然后报错 exception是 NullPointerException, 但是在Windows中是"",所以一切正常!
很奇怪!
大家有这方面经验的很帮忙啊.我的头很着急,我想尽快把这个问题解决掉.

解决方案 »

  1.   

    windows和linux区别太多啦if(null!=listcatPath&&!listcatPath.equals("")) {
    }不就可以了?
      

  2.   

    把你的代码改改不就行了
    if (listcatPath != null && !listcatPath.equals(""))平台之间的差异有时候很微妙的,getText()方法的定义规范里并没有要求不能返回null,所以你自己的程序必须学会去兼容它。
      

  3.   

    如果在windows中本不应该是""的情况下,到了Linux中还是显示为 NULL. 
      

  4.   

    getText()方法的定义规范里并没有要求不能返回null
    这就是为什么!
      

  5.   

    如果在windows中本不应该是""的情况下,到了Linux中还是显示为 NULL. 
      

  6.   

    getText
    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)
    这段看不懂.请指教!
      

  7.   

    getText
    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)
    这段看不懂.请指教!
      

  8.   

    getText
    public String getText()返回此 TextComponent 中包含的文本。如果底层文档为 null,则将给出 NullPointerException。注意,文本不是绑定属性,所以更改时不触发 PropertyChangeEvent。要侦听文本的更改,请使用 DocumentListener。 返回:
    文本 
    抛出: 
    NullPointerException - 如果文档为 null
    另请参见:
    setText(java.lang.String)--------------------------------------------------------------------------------
    看不懂就找个中文版的
      

  9.   

     try {
                            
                                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"
                                ....
      

  10.   

    String s = inputTextField.getText(); 
    s = (s == null)?"":s;if(s.equals("")) {
    //......
    }
      

  11.   

    关键是如果有一个正确地路径,在Linux下还是NULL.Path2 这个变量根本就进不去ModalWorker这个方法中. 会是和final定义有关系吗? 还是说在ModalWorker方法内的Path2变量和外面那个变量根本就是两个Object? 一个是一个具有实际路径字符串的String对象,另一个是一个NULL 对象. 所指向的内存物理地址是不同的?
    谢谢大家!
    对了,本人没有帮助日本人做事,也根本不懂什么事日语.只是想问大家这个问题.谢谢.