[vbox-dev] Java XPCOM SDK NullPointerException

Nikolay Igotti igotti at gmail.com
Tue May 31 07:31:00 GMT 2011


     Jan,

  Maybe your Eclipse somehow affect property setting. Following code 
works on my Mac (4.0.8 build):

import org.virtualbox_4_0.*;

public class Sample
{
     public static void main(String[] args)
     {
         VirtualBoxManager mgr = 
VirtualBoxManager.createInstance("/Applications/VirtualBox.app/Contents/MacOS");
         IVirtualBox vbox = mgr.getVBox();
         System.out.println("vbox "+vbox.getVersion());
         mgr.cleanup();
     }
}

And variant with setProperty() works for me too, but I use standalone 
javac/java. Try that to sort out
influence of your IDE.

   Nikolay.


On 5/30/11 5:17 PM, Jan Dillmann wrote:
> Hello list,
>
> for my current university project, I need to access VirtualBox instances using the vboxjxpcom.jar .
>
> However, I can't even get the minimal sample running. The following code
>
> 	public static void main(String[] args) {
> 		System.setProperty("vbox.home", "/Applications/VirtualBox.app/Contents/MacOS");
>
> 		VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
>
> 		IVirtualBox vbox = mgr.getVBox();
> 		System.out.println("VirtualBox version: " + vbox.getVersion());
> 		
> 		mgr.cleanup();
> 	}
>
> crashes at "VirtualBoxManager.createInstance" with the following exception:
>
> Exception in thread "main" java.lang.NullPointerException
> 	at org.mozilla.xpcom.Mozilla.initialize(Mozilla.java:632)
> 	at org.virtualbox_4_0.VirtualBoxManager.createInstance(VirtualBoxManager.java:104)
> 	at Main.main(Main.java:15)
>
> I'm developing with Eclipse Helios and Java 1.6 on a Mac OS X 10.6 using the latest VirtualBox and jar (4.0.8).
>
> Does anyone know how I can fix this? The jar is in the classpath and the vbox.home-Property is set.
>
> Thanks in advance,
> Jan
> _______________________________________________
> vbox-dev mailing list
> vbox-dev at virtualbox.org
> http://vbox.innotek.de/mailman/listinfo/vbox-dev





More information about the vbox-dev mailing list