1

I have created a JAVA application to get the IMDB ratings of movies. The application takes one command line argument (name of the movie) and displays the rating of the same. I have added the application to the right-click context menu. so, now when I right click I need the file name (without extension) to be passed as a command line argument. How can I do this?

I tried adding %1 as placeholder in the registry but it doesn't seem to work. The application works from the command line with an argument.

Can someone help me?

COMMAND LINE:

java -jar C:\NetBeansProjects\APPLICATION\dist\APPLICATION.jar daredevil

OUTPUT:

enter image description here

RIGHT CLICK MENU enter image description here

ERROR

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at application.IMDB.IMDBFetch(IMDB.java:67)
    at application.IMDB.URLParse(IMDB.java:54)
    at application.IMDB$4.run(IMDB.java:387)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$300(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

REGISTRY ENTRY

java -jar "C:\NetBeansProjects\APPLICATION\dist\APPLICATION.jar" "%1"
Martin Serrano
  • 3,727
  • 1
  • 35
  • 48
  • Well what do you receive in your java program? What's causing the NPE? – JP Moresmau Mar 03 '16 at 17:51
  • The name of the movie is received as a command line argument. Whn I right click on a file, the name of the file is suppossed to be received but that is not being received I guess, which causes the NPE. – Jithin Gangadharan Mar 03 '16 at 17:54
  • Yes I understand that. Modify your program to dump the value of the argument you actually receive, to ensure the issue is really in passing the argument. What would passing a wrong argument cause a NPE? – JP Moresmau Mar 03 '16 at 17:55

1 Answers1

0

put your jar file in your jre/lib/ext folder then compile your program without -jar Option.

Everything said about the classpath is true, but this is a consistent and sensible place for it to live.

you can find out your jre folder by looking at the JAVA_HOME environment variable on Windows.

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52