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.
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.