java - why does getResource give different result? -


bellow code, when run these code in ide works well, when run in dos command gives me error of nullpointexception. please give me hand. thanks!

     //first classloader     classloader classloader = testmainpath.class.getclassloader();     //show message     system.out.println("loader=" + classloader);     //     url r = classloader.getresource("testmainpath/testmainpath.class");     system.out.println("r=" + r);     string mainpath =r.getpath();     system.out.println(mainpath);     file sf = new file(mainpath + "/main/newfile");     system.out.println(sf.getpath());     system.out.println(sf.exists()); 

your problem because ide not launch app do. in case difference on classpath. check how ide launch program, classpath uses. verify class file expect when launch command line.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -