title: How to fix - Exception in thread "main" java.lang.NullPointerException - in Eclipse
body: <p>I wanted to create Cloudsim simulation in Eclipse IDE. I have make sure there is no significant error that should gives problem to the program. But when I run the program, this issue appear.</p>
  
  <hr>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  
  at org.cloudbus.cloudsim.Host.vmCreate(Host.java:221)
  at org.cloudbus.cloudsim.VmAllocationPolicySimple.allocateHostForVm(VmAllocationPolicySimple.java:92)
  at org.cloudbus.cloudsim.Datacenter.processVmCreate(Datacenter.java:443)
  at org.cloudbus.cloudsim.Datacenter.processEvent(Datacenter.java:216)
  at org.cloudbus.cloudsim.core.SimEntity.run(SimEntity.java:426)
  at org.cloudbus.cloudsim.core.CloudSim.runClockTick(CloudSim.java:523)
  at org.cloudbus.cloudsim.core.CloudSim.run(CloudSim.java:887)
  at org.cloudbus.cloudsim.core.CloudSim.startSimulation(CloudSim.java:188)
  at cloudsimProject.cloudsimSimulation.main(cloudsimSimulation.java:93)
  </code></pre>
  
  <hr>
  
  <p>I don't know which null should I change to fix this issue. This is the code.</p>
  
  <pre><code>    import java.util.ArrayList;
      import java.util.Calendar;
      import java.util.LinkedList;
      import java.util.List;
  
      import org.cloudbus.cloudsim.Cloudlet;
      import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
      import org.cloudbus.cloudsim.Datacenter;
      import org.cloudbus.cloudsim.DatacenterBroker;
      import org.cloudbus.cloudsim.DatacenterCharacteristics;
      import org.cloudbus.cloudsim.Host;
      import org.cloudbus.cloudsim.Log;
      import org.cloudbus.cloudsim.Pe;
      import org.cloudbus.cloudsim.Storage;
      import org.cloudbus.cloudsim.UtilizationModelFull;
      import org.cloudbus.cloudsim.Vm;
      import org.cloudbus.cloudsim.VmAllocationPolicySimple;
      import org.cloudbus.cloudsim.VmSchedulerSpaceShared;
      import org.cloudbus.cloudsim.core.CloudSim;
      import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
      import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
      import org.cloudbus.cloudsim.provisioners.RamProvisioner;
      import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
  
      public class cloudsimSimulation {
  
      /**
       * @param args
       */
      public static void main(String[] args) 
      {
          // TODO Auto-generated method stub
          int numUser=1;
          Calendar cal;
          cal = Calendar.getInstance();
          boolean traceFlag=false;
          CloudSim.init(numUser, cal, traceFlag);
  
          Datacenter dc = CreateDataCenter();
  
          DatacenterBroker dcb = null;
  
          try
          {
              dcb = new DatacenterBroker("DatacenterBroker1");
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
          List&lt;Cloudlet&gt; cloudletList = new ArrayList&lt;Cloudlet&gt;();
  
          long cloudLetLength = 40000;
          int pesNumber = 1;
          long cloudletFileSize = 300;
          long cloudletOutputSize = 400;
          UtilizationModelFull fullUtilize = new UtilizationModelFull();
  
          for(int cloudletId=0;cloudletId&lt;40;cloudletId++)
          {
              Cloudlet newCloudlet = new Cloudlet(cloudletId, cloudLetLength, pesNumber, cloudletFileSize, cloudletOutputSize, 
                  fullUtilize,fullUtilize,fullUtilize);
              newCloudlet.setUserId(dcb.getId());
              cloudletList.add(newCloudlet);
          }
          List&lt;Vm&gt; vmList = new ArrayList&lt;Vm&gt;();
  
          long diskSize = 20000;
          int ram = 2000;
          int mips = 1000;
          int bandwidth = 1000;
          int vCPU = 1;
          String VMM = "XEN";
  
          for(int vmId=0;vmId&lt;40;vmId++)
          {
              Vm virtualMachine = new Vm(vmId, dcb.getId(), mips, vCPU, ram, bandwidth, diskSize, VMM, 
                      new CloudletSchedulerTimeShared());
              vmList.add(virtualMachine);
          }
  
          dcb.submitCloudletList(cloudletList);
          dcb.submitVmList(vmList);
  
          CloudSim.startSimulation();
  
          List&lt;Cloudlet&gt; finalCloudletExecutionResults = dcb.getCloudletReceivedList();
  
          CloudSim.stopSimulation();
  
          int cloudletNo=0;
          for(Cloudlet c : finalCloudletExecutionResults)
          {
              Log.printLine("Result of cloudlet No " + cloudletNo);
              Log.printLine("**********************");
              Log.printLine("ID:"+c.getCloudletId()+ "Vm:"+c.getVmId()+ "status:"+c.getStatus()+ ",Execution Time:"+c.getActualCPUTime()+ ",Start:"+c.getExecStartTime()+ ",finish:"+c.getFinishTime() );
              Log.printLine("**********************");
              cloudletNo++;
          }
      }
  
      private static Datacenter CreateDataCenter()
      {
          List&lt;Pe&gt; peList = new ArrayList&lt;Pe&gt;();
  
          PeProvisionerSimple pProvisioner = new PeProvisionerSimple(1000);
  
          Pe core1 = new Pe(0, pProvisioner);
          peList.add(core1);
          Pe core2 = new Pe(1, pProvisioner);
          peList.add(core2);
          Pe core3 = new Pe(2, pProvisioner);
          peList.add(core3);
          Pe core4 = new Pe(3, pProvisioner);
          peList.add(core4);
  
          List&lt;Host&gt; hostlist = new ArrayList&lt;Host&gt;();
  
          int ram = 8000;
          int bw = 8000;
          long storage = 100000;
          Host host1 = new Host(0, RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList, 
                  new VmSchedulerSpaceShared(peList));
          hostlist.add(host1);
          Host host2 = new Host(1, RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList, 
                  new VmSchedulerSpaceShared(peList));
          hostlist.add(host2);
          Host host3 = new Host(2, RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList, 
                  new VmSchedulerSpaceShared(peList));
          hostlist.add(host3);
          Host host4 = new Host(3, RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList, 
                  new VmSchedulerSpaceShared(peList));
          hostlist.add(host4);
  
          String architecture="x86";
          String os = "Linux";
          String vmm="XEN";
          double timeZone = 5.0;
          double ComputecostPerSec = 3.0;
          double costPerMem=1.0;
          double costPerStorage=0.05;
          double costPerBW=0.10;
  
          DatacenterCharacteristics dcCharacteristics= 
                  new DatacenterCharacteristics(architecture, os, vmm, hostlist, timeZone, ComputecostPerSec, costPerMem, costPerStorage, costPerBW);
  
          LinkedList&lt;Storage&gt; SANstroage = new LinkedList&lt;Storage&gt;();
  
          Datacenter dc=null;
  
          try
          {
              dc = new Datacenter("Datacenter1", dcCharacteristics, new VmAllocationPolicySimple(hostlist), SANstroage, 1);
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
  
  
          return dc;
      }
  
      private static RamProvisioner RamProvisionerSimple(int ram) 
      {
          // TODO Auto-generated method stub
          return null;
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p>I hope you could help me fix this issue.</p>