Error:     java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference   Not getting anything, am confused!  Java code:  package com.listview;  import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView;   public class MainActivity extends Activity {    ListView lvAndroid;     @Override      protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      String[] arrAndroid=    {"Cupcake","Donut","Jellybean","Kitkat","Lollipop","Marshmellow","Nougat"};        ArrayAdapter adapt = new ArrayAdapter&lt;&gt;(this,R.layout.lv,arrAndroid);    lvAndroid=(ListView)findViewById(R.id.lvAndroid);      lvAndroid.setAdapter(adapt);   } }   Lv.xml  &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!--  Single List Item Design --&gt;  &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/label"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:padding="10dip"     android:textSize="10sp"     android:textStyle="bold" &gt; &lt;/TextView&gt;   Main activity:  &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.listview.MainActivity"&gt;  &lt;ListView     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/lvAndroid"     android:layout_alignParentTop="true"     android:layout_alignParentStart="true" /&gt;  &lt;/RelativeLayout&gt;
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
121649
I am unable to pass parameter from the lightning controller to the apex class. Whenever I use debug the passed value seems null.  JavaScript Controller  add : function(cmp,event,helper) {      event.target.parentNode.style.display = 'none';     document.getElementById("cartdiv").style.display = 'block';     var selectedAccount =event.target.id;      var act = cmp.get("c.Cartveg");     act.setParams({"s":selectedAccount});     act.setParams({"cartlist" : cmp.get("v.cart")});     act.setCallback(this,function(a){         cmp.set("v.cartitem",a.getReturnValue());     });            $A.enqueueAction(act);     cmp.set("v.whichButton", selectedAccount); }   Apex Class  @AuraEnabled public static List&lt;Vegetable__c&gt; Cartveg(string s,List&lt;Vegetable__c&gt; cartlist) {       system.debug(s);   List&lt;Vegetable__c&gt;  clist= [SELECT Id, Name , Price__c , img__c                                  FROM Vegetable__c where Name =:s];      clist.addAll(cartlist);      system.debug(clist);     return clist; }   Value of s is null. Please help
68403
I have this controller but I am getting this error      System.QueryException: List has no rows for assignment to SObject   public class MyController {     private final Account account;      public MyController() {         account = [SELECT Id, Name, Site FROM Account                     WHERE Id = :ApexPages.currentPage().getParameters().get('id')];             }      public Account getAccount() {         return account;     }      public PageReference save() {         update account;         return null;     } }
74626
I'm trying to fetch the contact record and showing on page using  its showing error      Unknown property EditContact_controller.wrapperClass.conList   Which thing is unknown.  here is my controller  public class EditContact_controller{     public List&lt;wrapperClass&gt; wrapClassList{get;set;}     public List&lt;contact&gt; conList;     public wrapperClass wc{get;set;}      public EditContact_controller(){         wrapClassList = new List&lt;wrapperClass&gt;();         conList = new List&lt;Contact&gt;();         conList = [SELECT Id, FirstName, LastName FROM Contact LIMIT 10];         For(Contact co : conList){             wc = new wrapperClass();             wc.flag = false;             wc.conWrap = co;             wrapClassList.add(wc);         }     }     public class wrapperClass{         public boolean flag{get;set;}         public Contact conWrap{get;set;}       }     }   Here is my VFPage  &lt;apex:page controller="EditContact_controller" tabStyle="Contact"&gt; &lt;apex:form id="frm"&gt;     &lt;apex:pageBlock title="Contact Records"&gt;          &lt;apex:repeat value="{!wrapClassList}" var="contactTable" id="cont_Table"&gt;             &lt;table&gt;                 &lt;tr&gt;                     &lt;th&gt; Action &lt;/th&gt;                 &lt;/tr&gt;                  &lt;tr&gt;                     &lt;th&gt; First Name &lt;/th&gt;                 &lt;/tr&gt;                  &lt;tr&gt;                      &lt;th&gt; Last Name &lt;/th&gt;                 &lt;/tr&gt;                   &lt;tr&gt;                     &lt;td&gt; &lt;apex:inputCheckbox value="{!contactTable.flag}"/&gt; &lt;/td&gt;                 &lt;/tr&gt;                  &lt;tr&gt;                     &lt;td&gt; &lt;apex:outputField value="{!contactTable.conList.FirstName}"/&gt; &lt;/td&gt;                 &lt;/tr&gt;                  &lt;tr&gt;                     &lt;td&gt; &lt;apex:outputField value="{!contactTable.conList.LastName}"/&gt; &lt;/td&gt;                 &lt;/tr&gt;               &lt;/table&gt;                    &lt;/apex:repeat&gt;      &lt;/apex:pageBlock&gt;  &lt;/apex:form&gt;
20599
I am receiving apex errors with the following code:   public with sharing class AddExistingSpecsExt {      public Specifications__c loadedSpec { get; private set; }  public AddExistingSpecsExt() {     String specId = ApexPages.currentPage().getParameters().get('id');     if (String.isBlank(specId)) return;      List&lt;Specifications__c&gt; candidates = [         SELECT Id, Name, Product__c FROM Specifications__c WHERE Id = :specId LIMIT 1     ];     if (!candidates.isEmpty()) loadedSpec = candidates[0]; }     public PageReference associate () {          Specifications__c candidates = new Specifications__c ( Id = Specifications__c.Product__c, Name = Specifications__c.Id);          try {             Database.update(candidates);         } catch (Exception error) {             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error while associating.' + error.getMessage()));         }          PageReference page = new PageReference('/' + candidates);          return page.setRedirect(true);     }      public PageReference cancel () {         PageReference page = new PageReference('/' + Null);         return page.setRedirect(true);             }  }   Attempting to add records to a related list through a custom button and small vf page.   The Error is Line 16      Invalid initial expression type for field Specifications__c.Id, expecting: Id   Any help?
18114
I have a method with an out parameter that tries to do a type conversion. Basically:  public void GetParameterValue(out object destination) {     object paramVal = "I want to return this. could be any type, not just string.";      destination = null; // default out param to null     destination = Convert.ChangeType(paramVal, destination.GetType()); }   The problem is that usually someone would call this like:  string output; GetParameterValue(output);   This will fail because of:  destination.GetType()   destination is null, so we can't call .GetType() on it. We also can not call:  typeof(destination)   because destination is a variable name not a type name.  So is there any way to get the type of an object that is set to null? I would think there would have to be a way to know what type a storage location is without it being assigned anything.    Just to give a bit more info, I am trying to make a utility method that will grab the output parameters of an Oracle stored procedure. The issue is that DbParameter.Value is of type object.  What would be ideal would be for the developers to do something like:  string val = GetParameterValue("parameterName");   The notable thing is that there is no casting of types. In practice, you don't know the lparam of the "equals", so I went with:  string val; GetParameterValue("parameterName", out val);   And figured within the method, I would know the destination type of the output variable. I guess that was a bad assumption. As an alternative, I also wrote the method:  public T GetParameterValue&lt;T&gt;(string paramName)   So the developers can do:  string val = GetParameterValue&lt;string&gt;("parameterName");   I find the explicit "string" declaration to be repetitive, especially since in practice, the destination if probably an object property and the oracle data type could change (think ORM):  MyObj.SomeProp = GetParameterValue&lt;MyObj.SomeProp.GetType()&gt;("parameterName");   But again, if MyObj.SomeProp is null, that .GetType() call fails. The VM has to know the type of MyObj.SomeProp, even when its null, right? or else how would it catch cast exceptions?    To partially solve my own problem, I can do:  MyObj.SomeProp = GetParameterValue&lt;typeof(MyObj).GetField("SomeProp").GetType()&gt;("parameterName");   The whole idea was to not have to explicitly use the Type in more than one place, so that if the data type changes, it only has to be changed in the destination object (MyObj.SomeProp) and in the DB. There has to be a better way...
94823
I am trying to create a button which will update a field value to null (RESET it). However, it's not working and not even giving any error. So when I click on the button, nothing happens.  lc.cmp:  &lt;aura:attribute name="myObj" type="Account" default="{'SObject':'Account'}"/&gt; &lt;lightning:input type="text" name="accountPhn" label="Enter Account Phone" value="{!v.myObj.Name}"/&gt; &lt;lightning:button label="Reset" onclick="{!c.resetMe}"/&gt;   lc.js:  resetMe : function(component, event, helper) {         //alert("Called");         component.set("v.accountPhn","");     }   Appreciate help around this.
103246
I can't seem to call the objects out on the database and onto a visualforce page using this set up:   public with sharing class HarborEventController {  private final Event__c event; public HarborEventController(ApexPages.StandardController controller) {     this.eventlist = (Event__c)controller.getRecord(); }   public Integer eventcount{get;set;} public HarborEventController (){    eventcount = [SELECT COUNT() FROM Event__c];     }   public list&lt;Event__c&gt; mainlist {get;set;}   public list&lt;Event__c&gt; displayevents(){     mainlist = new list&lt;Event__c&gt;();     String mainsoql = 'SELECT Id, Name__C, Message__c, Display_Date__c, FROM Event__c';      mainsoql += 'ORDER BY Display_date__c LIMIT :5';     mainlist = Database.query(mainsoql);     return mainlist; }   and the visualforce page :           &lt;apex:composition template="eh_base"&gt;           &lt;apex:define name="heros-content"&gt;             &lt;/apex:define&gt;       &lt;apex:define name="content"&gt;        &lt;section id="services-sec"&gt;          &lt;div class="container"&gt;             &lt;div class="row" style="padding-top: 60px;"&gt;       &lt;apex:outputPanel layout="block" rendered="{!AND(NOT(ISNULL(mainlist)),mainlist.size&gt;0)}"&gt;         &lt;apex:form id="blockofeventtorepeat"&gt;             &lt;apex:repeat value="{!mainlist}" var="evententry" id="repeat"&gt;                 &lt;div class="col-md-9"&gt;                    &lt;h3&gt;&lt;apex:outputLink styleClass="evententry-header block" value="{!$Page.eh_eventdetails}?id={!evententry.id}"&gt;{!evententry.Name__c}&lt;/apex:outputLink&gt;&lt;/h3&gt;                     &lt;apex:outputPanel &gt;                      &lt;p&gt;                          &lt;img src="{!URLFOR($Action.Attachment.Download, evententry.Attachments[0].Id)}" class="pull-left img-responsive" alt="" style="max-width:180px;max-height:100px"/&gt;                         {!evententry.Message__c}                      &lt;/p&gt;                        &lt;apex:outputLink styleclass="btn btn-sm btn-default" value="{!$Page.eh_eventdetails}?id={!evententry.id}"&gt;Read More&lt;/apex:outputLink&gt;                      &lt;/apex:outputPanel&gt;                 &lt;/div&gt;                 &lt;/apex:repeat&gt;                 &lt;/apex:form&gt;                 &lt;/apex:outputPanel&gt;                   &lt;/div&gt;             &lt;/div&gt;                 &lt;/section&gt;           &lt;/apex:define&gt; &lt;/apex:composition&gt;     Can anyone suggest how I can able to get the event data from the query and display it on a visualforce page in a repeat tag? I've tried everything and it doesn't work.  I've already tried passing the query from an anonymous user and the results were as expected
87958
I have a page where I am trying to show which ListViews a Project is in. I can get the data I want in the Developer Console by querying ListView. However, when I try to import the following query to my code I get the following exception: "Save error: sObject type 'ListView' is not supported." Query:  SELECT Id, Name FROM ListView WHERE SObjectType = 'Project__c'   As a workaround, I am trying to instantiate an Apex:StandardSetController for Project__c and call getListViewOptions(). Notice I am not calling getListViewOptions on my ApexPages.StandardController. The relevant bit that is not working:  public MyExtension(ApexPages.StandardController notUsed) {     debugListViews(); // yields bogus results } public MyExtension(ApexPages.StandardSetController notUsed) {     debugListViews(); // yields valid results } private void debugListViews() {     ApexPages.StandardSetController controller = new ApexPages.StandardSetController([         SELECT Id FROM Project__c LIMIT 1     ]);     for (SelectOption option : controller.getListViewOptions())     {         system.debug(option);     } }   This code works perfectly in Execute Anonymous. I see a list of SelectOption each of which has a valid Name/Id combination. However, when I run this code in my extension's constructor that takes in an ApexPages.StandardController, I get only one SelectOption that is clearly bogus. The Name is "All" and the Id is "000000000000000AAA". Note: the key prefix for ListView is "00B."  To add to the mystery, this code also works as expected in my extension constructor that takes in an ApexPages.StandardSetController.  This seems like it is a Salesforce bug, but I am not allowed to submit a Development Case for this org. Has anyone run into this before and found a workaround?
110175
I am receiving an error stated above on line 26**(listAccount1)**, can anyone guide me on how to solve it?  public class FRB_UpdateExceptionsforBatch {    public static void FRB_Exceptions(){    string FRBRecordTypeID = utility.getFRBProfileNameLabel();       List&lt;Account&gt; lstAccount = new List&lt;Account&gt;();         List&lt;Account&gt; lstAccount1 = new List&lt;Account&gt;();         List&lt;Account&gt; lstAccount2 = new List&lt;Account&gt;();         List&lt;Account&gt; lstAccount3 = new List&lt;Account&gt;();    lstAccount = [Select id,FRB_Firm_Check__c,Number_of_Exception__c,Number_of_exceptions_under_4_6_bucket__c,Number_of_exceptions_under_7_10_bucket__c,Number_of_exceptions_under_11_19_bucket__c,(select id,Account_Standing__c from Process_Adherence_Monitoring__r  where Status__C != 'Closed' AND  recordtypeId =: FRBRecordTypeID AND Account_Standing__c = '0-3 Days (Green - New Exception)' ) FROM Account WHERE FRB_Firm_Check__c = TRUE];     if(lstAccount.size()&gt;0){           for( Account acc : lstAccount )           {               List&lt;Process_Adherence_Monitoring__c&gt; lstCont = acc.Process_Adherence_Monitoring__r;                acc.Number_of_Exception__c = lstCont.size();               acc.FRB_Firm_Check__c = true;           }            update lstAccount;     }         //To update 4-6 bucket      lstAccount1 = [select Id, Name,FRB_Firm_Check__c, Number_of_exceptions_under_4_6_bucket__c,(select id,Account_Standing__c from Process_Adherence_Monitoring__r  where Status__C != 'Closed' AND  recordtypeId =: FRBRecordTypeID AND Account_Standing__c = '4-6 Days (Yellow - Outside Correction Timeframe)' ) from Account where FRB_Firm_Check__c = TRUE];        if(lstAccount1.size()&gt;0){           for( Account acc : lstAccount1 )           {               List&lt;Process_Adherence_Monitoring__c&gt; lstCont1 = acc.Process_Adherence_Monitoring__r;                              acc.Number_of_exceptions_under_4_6_bucket__c= lstCont1.size();               acc.FRB_Firm_Check__c = true;           }            update lstAccount1 ;       }         //To update 6-11 bucket         lstAccount2 =  [select Id, Name,FRB_Firm_Check__c, Number_of_exceptions_under_7_10_bucket__c,(select id,Account_Standing__c from Process_Adherence_Monitoring__r  where Status__C != 'Closed' AND  recordtypeId =: FRBRecordTypeID AND Account_Standing__c = '7-10 Days (Orange - Approaching Critical Timeframe)' ) from Account where FRB_Firm_Check__c = TRUE];        if(lstAccount2.size()&gt;0){           for( Account acc : lstAccount2 )           {               List&lt;Process_Adherence_Monitoring__c&gt; lstCont2 = acc.Process_Adherence_Monitoring__r;                acc.Number_of_exceptions_under_7_10_bucket__c= lstCont2.size();               acc.FRB_Firm_Check__c = true;           }           update lstAccount2 ;       }        //To update 11 bucket            lstAccount3 =  [select Id, Name,FRB_Firm_Check__c, Number_of_exceptions_under_11_19_bucket__c,(select id,Account_Standing__c from Process_Adherence_Monitoring__r  where Status__C != 'Closed' AND  recordtypeId =: FRBRecordTypeID AND Account_Standing__c = '11-19 Days (Red - Immediate Correction Required)' ) from Account where FRB_Firm_Check__c = TRUE];        if(lstAccount3.size()&gt;0){           for( Account acc : lstAccount3 )           {               List&lt;Process_Adherence_Monitoring__c&gt; lstCont3 = acc.Process_Adherence_Monitoring__r;                acc.Number_of_exceptions_under_11_19_bucket__c= lstCont3.size();               acc.FRB_Firm_Check__c = true;           }                              update lstAccount3 ;       }      }   }
19673
I am getting FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject. I know that it is because it is not returning any rows in the SOQL query but what I want is that if it returns any row, it should update ALO field on contact object, if it is null then ALO field should be set to null.  Here is my code:  ziptoLOD = [SELECT Id, Name, LOD__c             FROM Zip_3_to_LOD__c             WHERE Name =: contact.Extract_Zipcode__c ];  Zip_3_to_LOD__c ziptoLOD2 = (ziptoLOD != null) ? ziptoLOD : null;  if (ziptoLOD2 == null) {     contact.ALO__c = ' ';    } else {     System.debug(System.LoggingLevel.ERROR, 'Zip to LOD' + ziptoLOD2);     contact.ALO__c = ziptoLOD2.LOD__c; }   My code gets stuck at the SOQL query and gives me the list has no rows error.
93419
I am using Structure map like the MVC storefront by Rob Conery does and I have an AdminController and so to get to it I just type:  website/Admin/action   however if I miss spell the controller name I get the error below:  Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: key  There error occurs on this line:  Controller controller = ObjectFactory.GetInstance(controllerType) as Controller;   Does anyone have any ideas on how I can handle this error or not allow it to happen at all and maybe just goto a 404 page??  Cheers in advance
31499
Does assigning an unused object reference to null in Java improve the garbage collection process in any measurable way?  My experience with Java (and C#) has taught me that is often counter intuitive to try and outsmart the virtual machine or JIT compiler, but I've seen co-workers use this method and I am curious if this is a good practice to pick up or one of those voodoo programming superstitions?
7898
The StackExchange app crashes for me on every start when I click a link in the browser. It seems (based on the StackTrace) that the url parser causes a null pointer exception. I'm using 0.1.90.
24554
I have a lookup relationship.  If I just do the following query it works fine:  Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId]; system.debug('c:' + c);   However with the following I get an error:  Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId]; String c2 = (String) r.getSobject('field__r').get('fieldchild__c');   Error message:     FATAL_ERROR System.NullPointerException: Attempt to de-reference a   null object
18923
I am trying to write a test for a trigger that is firing a future apex callout :  The trigger calls the callBillingService method from this class:  public class BillingCalloutService {     //Implement business and callout logic methods here     @Future(callout=true)     public static void callBillingService(List&lt;Id&gt; recordIds) {         List&lt;Project__c&gt; projects = [Select Id, ProjectRef__c,Billable_Amount__c from Project__c Where Id = :recordIds];          List&lt;Project__c&gt; projectsToUpdate = new List&lt;Project__c&gt;();          String username = ServiceCredentials__c.getValues('BillingServiceCredential').Username__c;         String password = ServiceCredentials__c.getValues('BillingServiceCredential').Password__c;          String auth = username + ':' + password;         String encodedAuth = EncodingUtil.base64Encode(Blob.valueOf(auth));          for(Project__c p : projects) {              BillingServiceProxy.InvoicesPortSoap11 service = new BillingServiceProxy.InvoicesPortSoap11();             service.inputHttpHeaders_x = new Map&lt;String, String&gt;();             service.inputHttpHeaders_x.put('Authorization', 'Basic ' + encodedAuth);              BillingServiceProxy.project project = new BillingServiceProxy.project();             project.username = username;             project.password = password;             project.projectRef = p.ProjectRef__c;             project.billAmount = p.Billable_Amount__c;              if(service.billProject(project).equals('ok')){                 projectsToUpdate.add(new Project__c(ProjectRef__c = p.ProjectRef__c, Status__c = 'Billed'));             }         }         shouldIRun.stopTrigger();         upsert projectsToUpdate ProjectRef__c;     } }   Error     Methods defined as TestMethod do not support Web service callouts   Test Class  @IsTest private class BillingCalloutServiceTest {      @IsTest     private static void testBillingCalloutService() {     Account a = new Account(Name = 'Acme');     insert a;     Opportunity o = new Opportunity(Name='Test', StageName='Submitted Project', AccountId=a.Id, Amount=1000, CloseDate=Date.Today());     insert o;     Project__c p = new Project__c(Status__c='Running',Start_Date__c=Date.Today(),End_Date__c=Date.Today(),Billable_Amount__c=10000,ProjectRef__c='projectX',Opportunity__c=o.Id);     insert p;      insert new ServiceCredentials__c(Name='BillingServiceCredential',Username__c='toto', Password__c='azerty');      Test.startTest();     Test.setMock(HttpCalloutMock.class, new BillingCalloutServiceMock());       p.Status__c = 'Billable';       update p;     Test.stopTest();     // runs callout and check results     p = [select Status__c from Project__c where id =: p.id];     System.assertEquals('Billed', p.Status__c);     }  }
33737
If you take a look into this issue     I have provide an answer of using set&lt;Sobject&gt; instead using list&lt;Sobject&gt;  i.e.  if( !contacts.values().isEmpty() ){   set&lt;Contact&gt; setContacts = new set&lt;Contact&gt;();   for( Contact objCon : contacts.values() ){     if(!setContacts.contains(objCon)){         setContacts.add( objCon );     }   }  update new list&lt;Contact&gt;(setContacts); }   even if(!setContacts.contains(objCon)) is not needed  if( !contacts.values().isEmpty() ){   set&lt;Contact&gt; setContacts = new set&lt;Contact&gt;();   for( Contact objCon : contacts.values() ){         setContacts.add( objCon );   }  update new list&lt;Contact&gt;(setContacts); }   So is there any condition/use case where this answer might fail?