I am creating a function whereby I retrieve contacts via a webservice, but I want to create bookmarked/favorited contacts that are to be added into an SQLite database. After I add the favorite, and return to the activity I need to pass in the contact details to determine whether or not the contact has been marked as a favorite, and if it is, my FloatingActionButton would be of a certain set color. However (since I am using a webservice to retrieve the details first), I am doing this part of the code in the onPostExecute method of my async task. It supposedly passes in to a method in my SQLite Database helper, to check whether that contact's email exists or not, and if it exists, my FloatingActionButton is red, if not it stays my app's primary color.  This is the code in my onPostExecute      // check whether fav is selected     boolean found;     if (tvConEmail.getText().toString() != null) {         try {             found = db.findFavByEmail(tvConEmail.getText().toString());             if(found){                 favSelected = true;             }         } catch (NullPointerException e) {             e.printStackTrace();             favSelected = false;         }     }   However, no matter if the favorite is IN the database or not I catch the NullPointerException. This is my method in the database helper  public boolean findFavByEmail(String email) {         boolean exists = true;         SQLiteDatabase db = this.getReadableDatabase();         Cursor cursor = db.query(TABLE_FAVORITES,                 COLUMNS,                 "email = ?",                 new String[]{email},                 null, // group by                 null, // having                 null, // order by                 null); // limit          exists = (cursor.getCount() &gt;0);         cursor.close();          return exists;     }   How can I solve this problem and retrieve the boolean found without a NullPointerException? Or maybe my problem is with the findFavByEmail method which purpose is to check whether there is an existing record with the email passed in as a parameter? I have checked and logged, my email value is not null.
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?
18034
when i try to save the following code, i got the error below. Following same instructions given in this link, but still errors. Am i doing anything wrong here? please suggest.    @isTest private class WebSvcCalloutTest {     @isTest static void testEchoString() {         Account a = new Account(name='Tester',SAP_KUNNR__c='1172');         insert a;                       // This causes a fake response to be generated         Test.setMock(WebServiceMock.class, new WebServiceMockImpl());      } }   Error:  Save error: Method does not exist or incorrect signature: Test.setMock(Type, WebServiceMockImpl)    WebSvcCalloutTest.cls         @isTest global class WebServiceMockImpl implements WebServiceMock {    global void doInvoke(            Object stub,            Object request,            Map&lt;String, Object&gt; response,            String endpoint,            String soapAction,            String requestName,            String responseNS,            String responseName,            String responseType) {          sapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00 sap1 = new sapComDocumentSapSoapFunctionsMcS.Z_GSSMWFM_HNDL_EVNTRQST00();                Map&lt;String,String&gt; mapSAP = new Map&lt;String,String&gt; {};         sapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01 req = new sapComDocumentSapSoapFunctionsMcS.ZgssmbstDatarcrd01();               sapComDocumentSapSoapFunctionsMcS.ZGssmwfmHndlEvntrqst00Response_element ret =  sap1.ZGssmwfmHndlEvntrqst00('',req);         response.put('response_x', ret);     } }
90464
We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException.  Is there a reason why "null" has even been included in the language?  After all, if there were no "null", I would have no bug, right?  In other words, what feature in the language couldn't work without null?
8438
It's not a given that we're always connected to the internet, so why not include some offline features in the Stack Exchange App?  Something similar to Gmail app like    Currently the favorite questions are missing in the Android App.  Once they are back, can we have access to favorites in offline mode?  Once  connected to the internet again they could be synced to your device for the latest updates.  I tried to make a sample screen:    This image uses fake data
6359
What's the best way to get the last inserted id using sqlite from Java? Google is giving me different answers--some say select the last-insert-rowid; others say call statement.getGeneratedKeys(). What's the best route to take? (I just want to return the id, not use it for other inserts or anything.)
53993
I'm looking for a way to use fields from a data extension (that is the entry source for a journey) in the "Update Contact" activity.  I want to create a sort of log in a different data extension. Let's say I have a sourceDEthat is used by the journey and a journeylogDE where I would like to write the email of contact that's currently in the journey.  What should I write in the value field to get a value from the currently used record in the sourceDE?  I tried {{Contact.Attribute.sourceDE.email}}, but it did not return any values.   I would appreciate it if you could give me any tips how to fix this issue.
116377
I'm trying to populate the Contact lookup when a User creates a new related list object from the Contact page.  I am storing the Contact parameter in a Custom Setting so it can be changed when deploying to Production.  For some reason, whenever I try to bind this custom setting to the URL I get a leading '#' and none of the bindings work correctly.  This is despite using the URLENCODE function in the Visualforce  So when I put this (contactParameterId is != null)  &lt;apex:outputLink value="/{!relList.keyPrefixObject}/e?{!IF(relList.contactParameterId != null, 'CF{!URLENCODE(relList.contactParameterId)}={!URLENCODE(contact.Id)}&amp;', '')}retURL=/{!contact.Id}&amp;saveURL=/{!contact.Id}"&gt;&lt;/apex:outputLink&gt;   I get the URL      {URLENCODE(relList.contactParameterId)}={!URLENCODE(contact.Id)}&amp;retURL=/003U000000PL9LNIA1&amp;saveURL=/003U000000PL9LNIA1   What am I doing wrong?
49111
How do I use prepared statements in SQlite in Android?
21733
EmployeeNumber = string.IsNullOrEmpty(employeeNumberTextBox.Text)     ? null     : Convert.ToInt32(employeeNumberTextBox.Text),  I often find myself wanting to do things like this (EmployeeNumber is a Nullable&lt;int&gt; as it's a property on a LINQ-to-SQL dbml object where the column allows NULL values).  Unfortunately, the compiler feels that  There is no implicit conversion between 'null' and 'int'  even though both types would be valid in an assignment operation to a nullable int on their own. Using the null coalescing operator is not an option as far as I can see because of the inline conversion that needs to happen on the .Text string if it's not null. As far as I know the only way to do this is to use an if statement and/or assign it in two steps.  In this particular case I find that very frustrating because I wanted to use the object initializer syntax and this assignment would be in the initialization block... Does anyone know a more elegant solution?
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;
20509
I have a small code example I want to include in the Javadoc comment for a method.    /**  * -- ex: looping through List of Map objects --  * &lt;code&gt;  * for (int i = 0; i &lt; list.size(); i++) {  *      Map map = (Map)list.get(i);  *      System.out.println(map.get("wordID"));  *      System.out.println(map.get("word"));  * }  * &lt;/code&gt;  *   * @param query - select statement  * @return List of Map objects  */   The problem is the code example shows up in the Javadoc with no line breaks making it hard to read.    -- ex: looping through List of Map objects -- for (int i = 0; i list.size(); i++) { Map map = (Map)list.get(i); System.out.println(map.get("wordID")); System.out.println(map.get("word")); }  Parameters query - - select statement  Returns: List of Map objects    I guess I am wrong in assuming the code tag would handle line breaks.  What is the best way to format code examples in Javadoc comments ?
4667
Getting error with this code but I can't figure it out  trigger LeadConvert on Lead (after insert) {     list leadsToConvert = new list();      Database.LeadConvert lc;     string convertedStatus = '';     list convertStatusList = new list();     convertStatusList = [Select Id, MasterLabel                          from LeadStatus where IsConverted=true limit 1];     if(convertStatusList.size() &gt; 0){         convertedStatus = convertStatusList[0].MasterLabel;         }     else{              convertedStatus = 'Closed - Converted';          }      for(Lead l : trigger.New){         if(l.AutoConvert__c == true){             lc = new database.LeadConvert();             lc.setLeadId(l.ID);             lc.setDoNotCreateOpportunity(true);              lc.setConvertedStatus(convertedStatus);             leadsToConvert.add(lc);         }     }      list lcrList = new list();     lcrList = Database.convertLead(leadsToConvert); }
120685
It seems to me that a lot of my debugging time is spent chasing down null-reference exceptions in complex statements. For instance:  For Each game As IHomeGame in _GamesToOpen.GetIterator()   Why, when I get a NullReferenceException, can I get the line number in the stack trace, but not the name of the object that equals null. In other words, why:  Object reference not set to an instance of an object.   instead of  _GamesToOpen is not set to an instance of an object.   or  Anonymous object returned by _GamesToOpen.GetIterator() is null.   or  game was set to null.   Is this strictly a design choice, meant to protect the anonymity of the code or is there a compelling reason in compiler design not to include this information in the debug-time exception?
82536
I am upserting list of records based on externalId as follows:  List&lt;Database.upsertResult&gt; results = Database.upsert(lstRecords, CustomObject__c.External_Id__c,true);   The results returns as follows:  (Database.UpsertResult[getErrors=();                         getId=a1k0j000000P6CmAAK;                         isCreated=true;                         isSuccess=true;],   Database.UpsertResult[getErrors=();                         getId=a1k0j000000P6CNAA0;                         isCreated=false;                         isSuccess=true;])   The first record is inserted and 2nd record is updated.  Since I am upserting based on externalId, I need to know for which ExternalId the records have been successfully inserted or updated.   doesn't expose any methods. It returns SalesforceId and NOT externalId  I need a results structure like this:  (Database.UpsertResult[getErrors=();                         getExternalId = '1234';                         getId=a1k0j000000P6CmAAK;                         isCreated=true;                         isSuccess=true;],   Database.UpsertResult[getErrors=();                         getExternalId = '1235';                         getId=a1k0j000000P6CNAA0;                         isCreated=false;                         isSuccess=true;])   What would be the best way to achieve this.
84853
Comment on Duplicate Reference: Why would this be marked duplicate when it was asked years prior to the question referenced as a duplicate?  I also believe the question, detail, and response is much better than the referenced question.  I've been a C++ programmer for quite a while but I'm new to Java and new to Eclipse.  I want to use the  to visualize some data I'm working with.  This code is organized like this:  ./com ./com/touchgraph ./com/touchgraph/graphlayout ./com/touchgraph/graphlayout/Edge.java ./com/touchgraph/graphlayout/GLPanel.java ./com/touchgraph/graphlayout/graphelements ./com/touchgraph/graphlayout/graphelements/GESUtils.java ./com/touchgraph/graphlayout/graphelements/GraphEltSet.java ./com/touchgraph/graphlayout/graphelements/ImmutableGraphEltSet.java ./com/touchgraph/graphlayout/graphelements/Locality.java ./com/touchgraph/graphlayout/graphelements/TGForEachEdge.java ./com/touchgraph/graphlayout/graphelements/TGForEachNode.java ./com/touchgraph/graphlayout/graphelements/TGForEachNodePair.java ./com/touchgraph/graphlayout/graphelements/TGNodeQueue.java ./com/touchgraph/graphlayout/graphelements/VisibleLocality.java ./com/touchgraph/graphlayout/GraphLayoutApplet.java ./com/touchgraph/graphlayout/GraphListener.java ./com/touchgraph/graphlayout/interaction ./com/touchgraph/graphlayout/interaction/DragAddUI.java ./com/touchgraph/graphlayout/interaction/DragMultiselectUI.java ./com/touchgraph/graphlayout/interaction/DragNodeUI.java ./com/touchgraph/graphlayout/interaction/GLEditUI.java ./com/touchgraph/graphlayout/interaction/GLNavigateUI.java ./com/touchgraph/graphlayout/interaction/HVRotateDragUI.java ./com/touchgraph/graphlayout/interaction/HVScroll.java ./com/touchgraph/graphlayout/interaction/HyperScroll.java ./com/touchgraph/graphlayout/interaction/LocalityScroll.java ./com/touchgraph/graphlayout/interaction/RotateScroll.java ./com/touchgraph/graphlayout/interaction/TGAbstractClickUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractDragUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractMouseMotionUI.java ./com/touchgraph/graphlayout/interaction/TGAbstractMousePausedUI.java ./com/touchgraph/graphlayout/interaction/TGSelfDeactivatingUI.java ./com/touchgraph/graphlayout/interaction/TGUIManager.java ./com/touchgraph/graphlayout/interaction/TGUserInterface.java ./com/touchgraph/graphlayout/interaction/ZoomScroll.java ./com/touchgraph/graphlayout/LocalityUtils.java ./com/touchgraph/graphlayout/Node.java ./com/touchgraph/graphlayout/TGAbstractLens.java ./com/touchgraph/graphlayout/TGException.java ./com/touchgraph/graphlayout/TGLayout.java ./com/touchgraph/graphlayout/TGLensSet.java ./com/touchgraph/graphlayout/TGPaintListener.java ./com/touchgraph/graphlayout/TGPanel.java ./com/touchgraph/graphlayout/TGPoint2D.java ./com/touchgraph/graphlayout/TGScrollPane.java ./TG-APACHE-LICENSE.txt ./TGGL ReleaseNotes.txt ./TGGraphLayout.html ./TGGraphLayout.jar   How do I add this project in Eclipse and get it compiling and running quickly?
115896
I need some basic Unit Test writing assistance.   My method just runs a SOQL query to filter a contact list for service cloud. What's the best way to test it?  Here is the class:   public class ContactsListController{     public ContactsListController(ApexPages.StandardController stdController) {         this.acct = (Account)stdController.getRecord();     }      private final Account acct;       public List&lt;Contact&gt; getContacts() {         List&lt;Account&gt; acct =              [SELECT id              FROM Account              WHERE id = :ApexPages.currentPage().getParameters().get('id')];          List&lt;Contact&gt; results =             [SELECT Id, AccountId, Full_Name__c, Email, Phone, Title              FROM Contact               WHERE (AccountId = :acct AND No_Longer_with_Company__c = False)];          return results;     } }   The unit test inserts 50 new contacts, should I call to my getContacts method to get code coverage? Any pointers would be greatly appreciated.   Unit Test:   @isTest class ContactsListControllerTest {     static testMethod void testContactList (){         //Insert 50 test contacts         List&lt;Contact&gt; contacts = new List&lt;Contact&gt;();          for (Integer count = 0; count &lt; 50; count++) {             contacts.add(new Contact (FirstName = 'John'+count, LastName ='Doe'+count));         }          insert contacts;      }   }
78597
I keep getting the System.NullPointerException: Attempt to de-reference a null object on my trigger at line 21. I've attempted to add != null to that line and I get an error too. Please see the code below.  trigger UpdateDMAAccount on Account (before insert, before update) { //get set of Postal Codes from leads to be inserted or updated Set&lt;String&gt; BillingpostalCodes = new Set&lt;String&gt;(); for(Account l : trigger.new){ if(l.BillingPostalCode != null){     BillingpostalCodes.add(l.BillingPostalCode);  } } if(BillingpostalCodes.size() &gt; 0){ //create Map of custom object records with Name (PostalCode) as key Map&lt;String,DMA_Value__c&gt; validBillingPostalCode = new Map&lt;String,DMA_Value__c&gt;(); for(DMA_Value__c obj : [SELECT Id, Name, DMA_Value__c FROM DMA_Value__c WHERE Name IN :BillingpostalCodes]){     validBillingPostalCode.put(obj.Name,obj); } for(Account l : trigger.new){     if((Trigger.isInsert || trigger.oldMap.get(l.Id).BillingPostalCode != l.BillingPostalCode) &amp;&amp; validBillingPostalCode.containsKey(l.BillingPostalCode)){          l.DMA__c = validBillingPostalCode.get(l.BillingPostalCode).DMA_Value__c;     }     else if(trigger.oldMap.get(l.Id).BillingPostalCode != NULL || l.BillingPostalCode &amp;&amp; !validBillingPostalCode.containsKey(l.BillingPostalCode)){         //blank value if new PostalCode does not match a record in the Map         l.DMA__c = Null;     }   }  } }