Results 1 to 4 of 4
  1. #1
    pavel is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default

    with this message where is the problem?
    at com.vmware.vim25.mo.ServiceInstance.<init>(Service Instance.java:86)
    On line 86 of ServerInstance.java, which starts with a package declaration
    Java Code:
    package com.vmware.vim25.mo;
    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.

    db
    Last edited by DarrylBurke; 10-18-2010 at 12:18 PM.

  3. #3
    pavel is offline Member
    Join Date
    Oct 2010
    Posts
    13
    Rep Power
    0

    Default

    Thank you for the fast answear, Darryl.Burke :)

  4. #4
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default 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

  1. Replies: 6
    Last Post: 08-06-2009, 12:50 PM
  2. Replies: 6
    Last Post: 07-16-2009, 04:30 PM
  3. Replies: 1
    Last Post: 07-16-2009, 11:35 AM
  4. Exception in thread "main" java.lang.NullPointerException
    By jyothi.priyanka in forum New To Java
    Replies: 11
    Last Post: 03-11-2009, 04:18 AM
  5. Replies: 1
    Last Post: 07-16-2007, 07:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •