2011-11-09 37 views
0

嗨对不起,问的同样的问题..无法通过运行该命令提示符项目

我在Netbeans的

String build_path=getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); 
command.add(build_path+"i_view32.exe"); command.add(source_p+"/import_pal="+pal_file+"/convert="+ Dest_p+""); 

这是在NetBeans做工精细运行我的项目,但是当我从命令提示符

java -jar "D:\Pallete\dist\Pallete.jar" 

运行的版本给了我以下情况除外:

java.lang.NullPointerException 
     at pal.btn_OkActionPerformed(pal.java:214) 
     at pal.access$100(pal.java:22) 
     at pal$2.actionPerformed(pal.java:85) 
     at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 

当我点击确定按钮就在线路214

public static String jarpath ; 
public static String buildpath; 
    buildpath = getClass().getClassLoader().getResource("").getPath(); 
    jarpath=getClass().getProtectionDomain().getCodeSource().getLocation().getPath() 
+0

上面的代码是否会抛出NullPointerEx? – hellectronic

+0

@hellectronic:我做了更改,当我点击确定按钮时抛出异常 –

+0

@nirajdeshmukh什么行有'214'号码?可能你应该检查调用ClassLoader.getResource的结果(“”) –

回答

0

如果线214 getClass().getClassLoader().getResource("").getPath();抛出异常,并且getResource("") 是实际的代码,那么这个失败。它试图在空对象上调用getPath()

+0

你能告诉我它究竟是什么。 –

+0

我认为''getResource(“”)'会因为“”而抛出NPE。但由于错误在这一行,因此尝试检出哪个方法返回null。它是'getResource(“”)还是'getClassLoader()'?一个返回的对象是空的,在这个方法调用被应用,并且这将引发NPE。 – hellectronic

+0

有没有文件之间的区别:\ D:\ Interactives \ Pallete \ dist和D:\ Interactives \ Pallete \ dist –