I have been searching for an answer to this problem, and found a number of other similar questions. However, I believe I followed the code in the accepted answers and I'm still throwing a NullPointerException error when I try to run it. The question I looked at was . This was the code suggested for getting a column value from a cursor:   String id = cursor.getString( cursor.getColumnIndex("id") );   The answer made sense to me so I adapted it for my own function:  public String getSubjectId(String subject, String level) {     SQLiteDatabase db = this.getWritableDatabase();     Cursor subjectCursor = db.rawQuery("SELECT * FROM " + SUBJECTS_TABLE_NAME + " WHERE " + SUBJECTS_COL_2 + " = " + subject + " AND " + SUBJECTS_COL_3 + " = " + level, null);     String id = subjectCursor.getString(subjectCursor.getColumnIndex("ID"));     return id; }   When I run this I am throwing a NullPointerException error. I can't see a problem with the code and am confused about what the error means here. My understanding of the error is that it occurs when a variable is declared but it does not create an object, but I can't see where I have done that in my code. An explanation of what I have done wrong to trigger this error would be much appreciated, as I believe I have followed a number of online tutorials accurately.  Edit: I'm aware of  but my issue is I can't see a place where I am assigning an object as null so the solution isn't helping me.
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?
19319
I am creating a hosted app in SharePoint. I want to retreive all the custom list from SharePoint and then from the custom lists I want to fetch column values. I got 2 columns with the names title and link. Link is a hyperlink column containing urls. My question is some of my custom lists doesnt have the column name "link" and some has. But I want to retreive those list that has that column. And title column is in every custom list. Some of the list has the column name "link" but with no values.  Error message: 0x800a138f - Runtime errors in JavaScript: Unable to retrieve the property get_url for a reference that is undefined or null      function onSuccessItemFetch() {     // Now you can access the array of SP.ListItemCollection     for (var i = 0, length = listItemsCollection.length; i &lt; length; i++) {         var items = listItemsCollection[i];         var enumerator = items.getEnumerator();          while (enumerator.moveNext()) {             var listItem = enumerator.get_current();             if (typeof listItem.get_item('Link') != "undefined" &amp;&amp; typeof listItem.get_item('Link') != null) {             itemString += listItem.get_item('Title') + "&amp;nbsp" + "&amp;nbsp" + "&amp;nbsp" + "&amp;nbsp" + "&amp;nbsp" + "&amp;nbsp" + "&lt;a href='" + listItem.get_item('Link').get_url() + "'&gt;" + "öppna formulär" + "&lt;/a&gt;" + "&lt;/br&gt;";  //oListItem.get_item('Datum')             $('#divAllaListItems').html(itemString);             }         }     } }   It works fine when I want to retrieve all the custom list titles and the title column values.
57036
When I used to create the record in Event object it is showing error like:     Error: Invalid Data.   Apex trigger General_Event_Trigger caused an unexpected exception, contact your administrator: General_Event_Trigger: execution of BeforeINsert caused by: System.NullPointerException: Attempt to de-reference a null object: Class.EventClass.updateNewCustomFieldsEvent: line 369, column 1   Trigger code:  trigger General_Event_Trigger on Event (...) {     if (trigger.isBefore)     {         if (trigger.isInsert)         {             EventClass.updateNewCustomFieldsEvent(trigger.new);         }         else if (trigger.isUpdate)         {             EventClass.updateNewCustomFieldsEvent(trigger.new);         }     } }   Apex class:  public static void updateNewCustomFieldsEvent(List&lt;Event&gt; eventList) {     for (Event eve : eventList)     {         if (Administrators__c.getInstance().Update_field_Last_Modified_End_User__c)         {             String userIdString = eve.LastModifiedById;             eve.Last_Modified_By_End_User__c = userIdString.subString(0, 15);             eve.Last_Modified_Date_End_User__c = eve.LastModifiedDate;         }     } }
108596
I have a custom object that I want to set a unique key based on on lookup values. When I tried to create a workflow update I was blowing past the size limit so I developed it into a trigger and it seems to be working as intended.   I thought since I am already developing a field update trigger, I might as well add on a default name method so everything is contained into one file as opposed to having workflow and triggers updating the record.   When I introduced this method it returns "null null".   public static void setRecordName(List&lt;Responsible_Party__c&gt; newList) {     for(Responsible_Party__c r : newList)     {         r.Name = r.Practice__r.Name + ' ' + r.User__r.Name;     } }   Where practice is a lookup to another custom object and user is a lookup to the user object.   If I change the values to just use the field:  public static void setRecordName(List&lt;Responsible_Party__c&gt; newList) {     for(Responsible_Party__c r : newList)     {         r.Name = r.Practice__c + ' ' + r.User__c;     } }   I get "a1Gg00000049v9xEAA 005A0000006ykwnIAA". How can I get the names to display and not null?
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;     } }
6749
What are the best workarounds for using a SQL IN clause with instances of java.sql.PreparedStatement, which is not supported for multiple values due to SQL injection attack security issues: One ? placeholder represents one value, rather than a list of values.  Consider the following SQL statement:  SELECT my_column FROM my_table where search_column IN (?)   Using preparedStatement.setString( 1, "'A', 'B', 'C'" ); is essentially a non-working attempt at a workaround of the reasons for using ? in the first place.    What workarounds are available?
102897
Anyone working on the Android ('gPhone') have or know of a place where I can find a good ORM tool for it? The code is written in Java, and the database is SQLite. What I would like to find is a tool that given the object definition, can auto-generate the tables and the CRUD functions (that would be awesome), or, barring that, a tool that can take the table definition, the object definition, and auto-generate the CRUD functionality. The rub is that all of this must happen within the Android framework, which has its own conventions as to how database access works.
105631
Please consider the below scenario:   I have an Application__c object. I have a trigger on that (for simplicity, coded directly in trigger) which does one thing if the record name is Error then throws exception.     trigger ApplicationTrigger on Application__c (before insert, after update){          if(trigger.new[0].Name == 'Error'){             Application__c application;             System.debug(application.Name);         } }    Now I am running below code:     Now notice the catch statement is not executing, means system was not able to catch the exception. It came as the Fatal Error.   This is kind of a big issue where if there is null pointer or any other exception in trigger and exception handling code will not be able to do anything. Not even logging since it never reaches to catch block.   Let me know if you guys ever faced such situation and if yes what you did to make sure that it is properly caught.
64308
I am looking for a free tool to load Excel data sheet into an Oracle database. I tried the Oracle SQL developer, but it keeps throwing a NullPointerException. Any ideas?
42604
here is my code in which i am trying to get the product name from opportunity line item but its returning back NULL value. can anyone please help me to get that product name. I can get id from product2 but i want the name of product so that i can abbreviate it and can store it in Order_Name__c field of orderItem. After adding the product only i am firing this trigger.     public class Procuct_Adding_To_Order{  public static void productOrder(List&lt;OpportunityLineItem&gt; oli){     system.debug('-----------------------');      set&lt;id&gt; prodset = new set&lt;Id&gt;(); for(OpportunityLineItem item : oli) {   prodSet.add(item.product2id); } // collect products Map&lt;Id, product2&gt; prodMap = new Map&lt;Id, Product2&gt;([select name from product2 where id in :prodSet]);   // create a map for OLIid &amp; corresponding Product Name Map&lt;Id, string&gt; OLIprodMap = new Map&lt;Id, string&gt;();  for(OpportunityLineItem item : oli) {  OLIprodMap.put(item.id, OLIprodMap.get(oli.product2id).name); //getting Error in this line. }      set&lt;Id&gt; setOppId = new set&lt;Id&gt;();      for(OpportunityLineItem obj: oli){          setOppId.add(obj.OpportunityId);      }      list&lt;opportunity&gt; needed = [Select Master_Opportunity__c from opportunity Where Opportunity.id =: setOppId];         List&lt;OrderItem&gt; orderIt = new List&lt;OrderItem&gt;();     for(Order ord: [Select id from Order where opportunityId =: needed[0].Master_Opportunity__c])       {        for(OpportunityLineItem o : oli)        {           OrderItem op = new OrderItem();          op.Opportunity_del__c = needed[0].Master_Opportunity__c;          op.orderId = ord.id;         op.Order_Name__c = o.product2Id;         system.debug('-----------------------3333333333333333333333'+ o.Product2Id);         op.PriceBookEntryId = o.PriceBookEntryId;         op.Quantity = o.Quantity;         op.UnitPrice = 100;         orderIt.add(op);            }          }     upsert orderIt;  } }
121895
I have a trigger and a class that seem to be causing an insert fail in Dataloader.  I am trying to insert 200 records to see if an error is generated before moving these to production. I'm just inserting the mandatory fields such as Name, Owner, Market, Customer_Success_Manager__c, and Business Unit.   Each time I get an error:     UpdateCSMTeam:execution of AfterInsertcaused by: System.DmlException:   Insert failed. First exception on row 0 with id01MJ0000009gXthMAE;   first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an   insert call: [Id]Class.UpdateCSM.updateTeamMem . I've listed the class   and trigger below.   APEX CLASS  public class UpdateCSM {             public static void updateTeamMember(List&lt;Account&gt; accounts) {                     List&lt;AccountShare&gt; ashareLIST = new List&lt;AccountShare&gt;();                     List&lt;AccountTeamMember&gt; ATM = new List&lt;AccountTeamMember&gt;();                    Set&lt;String&gt; rmMember = new Set&lt;String&gt;();                     Map&lt;ID, ID&gt; acctToBRepMap = new Map&lt;ID, ID&gt;();                      for(Account a:accounts){                              AccountShare caSharingRule = new AccountShare();                                caSharingRule.AccountId = a.Id;                                caSharingRule.OpportunityAccessLevel = 'Edit';                                caSharingRule.CaseAccessLevel = 'Edit';                                caSharingRule.AccountAccessLevel = 'Edit';                                caSharingRule.UserOrGroupId = a.Customer_Success_Manager__c;                                ashareLIST.add(caSharingRule);                                    if(a.Customer_Success_Manager__c!= null){                                   AccountTeamMember Teammemberad=new AccountTeamMember();                 Teammemberad.AccountId=a.id;                 Teammemberad.UserId=a.Customer_Success_Manager__c;                 Teammemberad.TeamMemberRole = 'Customer Success Manager';                                   ATM.add(Teammemberad);                             if(!ATM.isEmpty()){                                    insert ATM;                                              insert ashareLIST;                                                         if(a.Customer_Success_Manager__c==null){                                            list&lt;AccountTeamMember&gt; ratm = [SELECT UserId                                                                             FROM AccountTeamMember                                                                             WHERE (TeamMemberRole = 'Customer Success Manager')                                                          AND AccountId =:a.id];                                             if(ratm.size()&gt;0)                                                 delete ratm;                                        }                                    }                                 }                            }                         }                    } ...   APEX TRIGGER  trigger UpdateCSMTeam on Account (After update, After insert){         UpdateCSM.updateTeamMember(trigger.new); }
102393
What would you consider to be the best exception type to throw when an extension method is called on a null instance (where the extension method does not allow it)? Since extension methods are nothing but static methods you could argue that it should be ArgumentNullException, but on the other hand they're used like instance methods so it might be more natural to use the NullReferenceException. Let's take the following example:  public static string ToInvariantString(this IFormattable value, string format) {     return value.ToString(format, CultureInfo.InvariantCulture); }   This way a NullReferenceException will be thrown if the value parameter is null.   The other example would be:  public static string ToInvariantString(this IFormattable value, string format) {     if (value == null) throw new ArgumentNullException("value");     return value.ToString(format, CultureInfo.InvariantCulture); }   EDIT: In some of the answers you have pointed out that an extension methods can be called like a static method and in those cases a null reference exception would be wrong, which is a great point, and actually one of my concerns, not sure why I forgot to mention that in the question in the first place.   Someone also pointed out that it's wrong to throw a NullReferenceException, and yes, it is. That's why I don't throw it, I just let it happen (let the CLR throw it) by not guarding the method.  I think I favor the ArgumentNullException (that's what I've use so far) but I still think there is at least room to argue for an against the NullReferenceException since it seems more natural in most places where the method is going to be used.
37897
There are situations, where it is practical to have a type-cast return a null value instead of throwing a ClassCastException. C# has the as operator to do this. Is there something equivalent available in Java so you don't have to explicitly check for the ClassCastException?
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.
56570
I have a database table that looks like:   create table answers(    id int not null,    question_id int not null,    answer text null )   This table was originally build by Hibernate using the @Lob attribute for the "answer" column.  I did not realize it at the time, but when setup that way, Hibernate stores an OID in the column instead of the actual text.  Everything works fine when I use Hibernate to retrieve the values since it automatically converts the OID to the CLOB string, however it is becoming a performance problem and I'd like to get rid of the OID.   select * from answers ID     QUESTION_ID     ANSWER =============================== 1       123             55123 2       234             51614 3       345             56127 should be ID     QUESTION_ID     ANSWER =============================== 1       123             Male 2       234             203-555-1212 3       345             555 Main St. New York, NY    My desire is to add an extra column to the table "ANSWER_VALUE TEXT" and do something like below to get the actual value into the table, then change Hibernate around to not use the @Lob designator   update answers set ANSWER_VALUE= getValueFromOID(ANSWER)   Does that "getValueFromOID" function exist?  If not, could I get some pointers on how to create one or at least how to fetch the actual value of an OID?  Thanks
56441
I am currently programming a trigger on Opportunities.   I created a test class for this and in my Sandbox I created an account, contact and opportunity. When I try to reference them   Opportunity Opp = [SELECT id from Opportunity where name = 'Test1'];    and then start my   Test.startTest();         Opp.StageName = 'PO in (100%)';          update Opp;         Test.stopTest();   It just errors and shows that Opp returns 0 rows. However when I paste my first bit of code in 'Execute Anonymous' it returns a row and the correct info.   Does this mean I have to create an account, contact, quote and all necessary fields in my test class?
100093
I am using the following code in selenium, but I am not able to retrieve data from database. I am getting the errors "The result set has no current row"  My code is   public class Auto {      public static void main(String[] args) throws InterruptedException, SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException     {           Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");         System.out.println("Driver loaded");           Connection con=DriverManager.getConnection("jdbc:sqlserver://192.168.*****\\SQLEXPRESS/*****_DW/EPS:****;user=******;password=******; ");          System.out.println("Driver loadedd");       java.sql.Statement stmt= con.createStatement();     ResultSet rs=stmt.executeQuery("select * from [*****_DW].[dbo].dim_grantee ");      System.out.println("Query executed");      while (rs.next());     {         String Name=rs.getString("NAME");          System.out.println("Name is");     }   }