Results 1 to 9 of 9
- 06-14-2009, 09:05 PM #1
[SOLVED] java.lang.NullPointerException
:confused:
Error:Java Code:import java.io.*; /** * This program executes an external program. * @author http://www.rgagnon.com/javadetails/java-0014.html - adapted * */ public class ExecuteExternalProgram { public static void main(String[] args) { try { [B] Process p = Runtime.getRuntime().exec (System.getenv("C:\\Program Files\\Java\\jdk1.6.0_14\\bin\\jconsole")); p.waitFor();[/B] } catch (Exception err) { err.printStackTrace(); } } }
java.lang.NullPointerException
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at ExecuteExternalProgram.main(ExecuteExternalProgram .java:13)Last edited by jon80; 06-14-2009 at 09:09 PM.
- 06-14-2009, 10:41 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
This
is returning null.Java Code:System.getenv("C:\\Program Files\\Java\\jdk1.6.0_14\\bin\\jconsole")
"getenv" is for getting environement variables, and when the requested variable doesn't exist (as
doesn't) it returns null, and exec throws an NPE when called with null.Java Code:"C:\\Program Files\\Java\\jdk1.6.0_14\\bin\\jconsole"
- 06-15-2009, 05:23 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Adding more, just try to debug the code and see before asking such questions lol. And also if you have find the solution for your question, if you can put a comment back there. It's much better. :)
- 06-15-2009, 06:49 AM #4
I thought that this was not named a Rant forum...
- 06-15-2009, 08:47 AM #5
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
I don't know where you are seeing any rants, although one is now about to come.
I have seen multiple questions from you here, and most of them could be solved by simply taking two seconds of actually looking at what you are doing. And for the others you have gotten good advice and seem to take umbrage at it.
Oh, well, another addition to the ignore list.
- 06-17-2009, 06:10 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes jon, think about what masijade says here seriously.
- 06-17-2009, 07:11 AM #7
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Yes jon... sometimes you post without thinking.
If you can't solve something, don't just immediately post on the forum. Try to solve it, read API docs, etc. Most of the time it's far better (and sometimes easier) for you to find the problem than it is to have others find it for you.
Also, Runtime.exec executes system console commands. If you are executing a java program, use java MyApp, or if it is a jar file use java -jar MyJar.jar. For other programs (though yours appears to be a java application) see this thread. It's long and has quite a few errors and some guesswork, but we did get it eventually.Last edited by Singing Boyo; 06-17-2009 at 07:13 AM.
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 06-17-2009, 09:00 AM #8
I leave it up to you to think whatever you like, and without feeling the need to justify myself, it's perfectly normal that people ask for help when they are stuck. I'm not sure why this seems to sound personal, however, I've seen a lot of posts that seek help that do not have "rant" kind of comments looking down on newbies.
If you have a problem helping other people, it would be just polite to ignore the forum than insulting other members! Why have you setup a forum after all??
Btw, I do look up the API books etc just for your frigging knowledge!
Cheers.Last edited by jon80; 06-17-2009 at 09:03 AM.
- 06-19-2009, 04:54 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
No here insulting on you jon. What they want to do is helping you in your questions. But not just giving a code segment or a hint in straightly. They(including me) want to guide you to the solution while learning related stuff. That's why we ask from you to search on API, Forum a and web before asking question.
You ask a question, and within couple of minutes/hours you mark the thread as solved. That means you found the solution before we commenting on it. So what my suggestion is, if you have spend some times on that way, the way you found the solution, it's much useful to you.
Similar Threads
-
java.lang.NullPointerException
By vasavi.singh in forum New To JavaReplies: 3Last Post: 02-28-2009, 05:41 AM -
java.lang.NullPointerException
By vasavi.singh in forum New To JavaReplies: 1Last Post: 02-27-2009, 12:36 PM -
java.lang.NullPointerException
By vasavi.singh in forum New To JavaReplies: 2Last Post: 02-27-2009, 10:11 AM -
java.lang.NullPointerException
By stevemcc in forum AWT / SwingReplies: 2Last Post: 02-08-2008, 09:01 AM -
java.lang.NullPointerException
By ravian in forum New To JavaReplies: 1Last Post: 01-13-2008, 07:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks