Results 1 to 4 of 4
- 10-18-2010, 10:33 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 13
- Rep Power
- 0
Exception in thread "main" java.lang.NullPointerException
Hi everyone.
I try to make this program:
package com.vmware.vim25.mo.samples;
import java.net.URL;
import com.vmware.vim25.*;
import com.vmware.vim25.mo.*;
/**
* Sample code to show how to use the Managed Object APIs to power off VM.
* @author Steve JIN (sjin@vmware.com)
*/
public class VMpoweroff
{
public static void main(String[] args) throws Exception
{
ServiceInstance si = new ServiceInstance(new URL("http://10.17.218.174/sdk"), "root", "password", true);
Folder rootFolder= si.getRootFolder();
ManagedEntity[] mes = rootFolder.getChildEntity();
for(int i=0; i<mes.length; i++)
{
if(mes[i] instanceof Datacenter)
{
Datacenter dc = (Datacenter) mes[i];
Folder vmFolder = dc.getVmFolder();
ManagedEntity[] vms = vmFolder.getChildEntity();
for(int j=0; j<vms.length; j++)
{
if(vms[j] instanceof VirtualMachine)
{
VirtualMachine vm = (VirtualMachine) vms[j];
System.out.println((vm.getName()));
VirtualMachineSummary summary = (VirtualMachineSummary) (vm.getSummary());
System.out.println(summary.toString());
VirtualMachineRuntimeInfo vmri = (VirtualMachineRuntimeInfo) vm.getRuntime();
if(vmri.getPowerState() == VirtualMachinePowerState.poweredOn
&& "Ubuntu704Srv".equals(vm.getName()))
{
Task task = vm.powerOffVM_Task();
task.waitForTask();
System.out.println("vm:" + vm.getName() + " powered off.");
}
}
}
}
}
si.getServerConnection().logout();
}
}
And it is coming this mistake:
Exception in thread "main" java.lang.NullPointerException
at com.vmware.vim25.mo.ServiceInstance.<init>(Service Instance.java:86)
at com.vmware.vim25.mo.ServiceInstance.<init>(Service Instance.java:69)
at VMpowerOperation.VMpoweroff.main(VMpoweroff.java:2 0)
with this message where is the problem?
I will be happy if someone can help me.
- 10-18-2010, 11:15 AM #2
with this message where is the problem?On line 86 of ServerInstance.java, which starts with a package declarationat com.vmware.vim25.mo.ServiceInstance.<init>(Service Instance.java:86)and which is in a constructor (as evinced by "<init>"), the code is attempting to dereference a null reference, or program logic is explicitly constructing and throwing a NullPointerException.Java Code:package com.vmware.vim25.mo;
dbLast edited by DarrylBurke; 10-18-2010 at 11:18 AM.
- 10-18-2010, 03:24 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 13
- Rep Power
- 0
Thank you for the fast answear, Darryl.Burke :)
- 08-22-2011, 08:31 AM #4
Member
- Join Date
- Aug 2011
- Posts
- 1
- Rep Power
- 0
Please check that URL is given correctly..
In the stmt
ServiceInstance si = new ServiceInstance(new URL("http://10.17.218.174/sdk"), "root", "password", true);
Make sure that the port number "8333 for https" (or) "8222 for http" must be followed by the ip address of the host machine... and root means the username and password is password.
For example my ip with the port is as follows:
ServiceInstance si = new ServiceInstance(new URL("http://192.168.11.115:8333/sdk"), "root", "password", true);
Regards,
Murthy.
Similar Threads
-
Exception in thread "main" java.lang.NullPointerException
By syarizma in forum Advanced JavaReplies: 6Last Post: 08-06-2009, 11:50 AM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 6Last Post: 07-16-2009, 03:30 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 1Last Post: 07-16-2009, 10:35 AM -
Exception in thread "main" java.lang.NullPointerException
By jyothi.priyanka in forum New To JavaReplies: 11Last Post: 03-11-2009, 03:18 AM -
ArrayList: Exception in thread "main" java.lang.NullPointerException
By susan in forum New To JavaReplies: 1Last Post: 07-16-2007, 06:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks