In a newly published game (android) that utilises a remote database to get data, I get daily many app crashes reports that I cannot reproduce or i have not encountered in my tests over several real devices and virtual devices. The top crash report is:  java.lang.RuntimeException:    at android.app.ActivityThread.performLaunchActivity    (ActivityThread.java:2805)   at android.app.ActivityThread.handleLaunchActivity  (ActivityThread.java:2883)   at android.app.ActivityThread.-wrap11 (Unknown Source)   at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1613)   at android.os.Handler.dispatchMessage (Handler.java:106)   at android.os.Looper.loop (Looper.java:164)   at android.app.ActivityThread.main (ActivityThread.java:6523)   at java.lang.reflect.Method.invoke (Native Method)      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run  (RuntimeInit.java:438)    at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:857) Caused by: java.lang.NullPointerException:     at com.my.app.activity.LevelActivity.onCreate (LevelActivity.java:82)    at android.app.Activity.performCreate (Activity.java:7023)    at android.app.Activity.performCreate (Activity.java:7014)     at android.app.Instrumentation.callActivityOnCreate  (Instrumentation.java:1214)    at android.app.ActivityThread.performLaunchActivity  (ActivityThread.java:2758)   for example the LevelActivity.java:82 :          levelNo = MainActivity.dbHelper.GetLevelById(Constant.CATE_ID, Constant.SUB_CAT_ID);   and the oncreate until line with the NPE:   public void onCreate(@Nullable Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_level);     Utils.transparentStatusAndNavigation(LevelActivity.this);     layout = findViewById(R.id.layout);     if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {         layout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);     }     toolbar = findViewById(R.id.toolBar);     setSupportActionBar(toolbar);     getSupportActionBar().setTitle(R.string.select_level);     toolbar.setNavigationOnClickListener(new View.OnClickListener() {         @Override         public void onClick(View view) {             onBackPressed();         }     });        recyclerView.setLayoutManager(new LinearLayoutManager(LevelActivity.this));     levelNo = MainActivity.dbHelper.GetLevelById(Constant.CATE_ID, Constant.SUB_CAT_ID);   i don't know where to begin since I have never encountered this error or similar crash  All crashes related to this app are: java.lang.NullPointerException  this is not a duplicate question as the methods described in the proposed original question do not apply here.  I cannot reproduce the error, how can I debug?  Not all headaches can dissapear with aspirin
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?
81630
Why does this test program result in a java.lang.IllegalMonitorStateException?  public class test {     static Integer foo = new Integer(1);     public static void main(String[] args) {         synchronized(foo) {             foo++;             foo.notifyAll();         }         System.err.println("Success");     } }   Result:  Exception in thread "main" java.lang.IllegalMonitorStateException         at java.lang.Object.notifyAll(Native Method)         at test.main(test.java:6)
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.
58461
Consider the code:  PreparedStatement ps = null; ResultSet rs = null; try {   ps = conn.createStatement(myQueryString);   rs = ps.executeQuery();   // process the results... } catch (java.sql.SQLException e) {   log.error("an error!", e);   throw new MyAppException("I'm sorry. Your query did not work."); } finally {   ps.close();   rs.close(); }   The above does not compile, because both PreparedStatement.close() and ResultSet.close() throw a java.sql.SQLException.  So do I add a try/catch block to the finally clause?  Or move the close statements into the try clause?  Or just not bother calling close?
91490
Possible Duplicate:          When should I create a checked exception, and when should I make a runtime exception?  For example, suppose I created the following class:  public class Account {     private float balance;      /* ... constructor, getter, and other fields and methods */      public void transferTo(Account other, float amount) {         if (amount &gt; balance)             throw new NotEnoughBalanceException();         /* ... */     } }   How should I create my NotEnoughBalanceException? Should it extend Exception or RuntimeException? Or should I just use IllegalArgumentException instead?
24091
This is a bit of a more unusual bug to report:    The screenshot above is unedited - the black box is rendered by the Stack Exchange application.  Phone:  running Android 4.0.4 (ICS)
98616
I can hookup to AppDomain.CurrentDomain.UnhandledException to log exceptions from background threads, but how do I prevent them terminating the runtime?
108718
This  confirms that the Android app is using two different loaders since last year, but just today I've noted that, at the questions page, it is using them simultaneously. I've never noted this, so I believe this bug was recently created.  I hope the following gif is clear enough to show the issue. Also, note that the bigger loader is "freezing".    SE Android App Version: 1.0.60 My Android OS Version: 5.0.2  Still observed in version 1.0.89
12503
Related to .  Any advice on fixing the problem below?  After a lot of experimentation with the program, I have discovered several things.   It crashes relatively consistently (90% of the time or so) upon running the line of code, Set Message = New CAPICOM.EncryptedData.  Note that the line above this is merely Dim Message As CAPICOM.EncryptedData. The function that makes that call does not crash when called earlier in the program's execution.  Binary search for error does not work to find the problem, since calling the function in some places mysteriously, unreliably prevents the bug from happening.  Sometimes rebuilding the program seems to impact if the bug shows up.  Yes, it is a heisenbug.  The same issues apply with temporal binary search for error.  Spending 5 hours comparing two versions of the program only to discover that both versions have the bug even though only one of them is currently showing the symptoms is not very productive. The crash is due to an access violation 0xC00000005 Running WinDbg (the windows debugger) shows that there is only one line of code which reads this memory location, LoadPicture(szTmpBMP).  It is called at the end of a scary function which grabs the picture out of a resource and sticks it in a temp file.  I was scared enough of this function that, for the sake of testing, I replaced it with a call to LoadPicture("testcra.bmp"), then didn't call the scary resource function for that bitmap.  This did not help.  Removing this call to loadpicture entirely also did not help, though the debugger could no longer find any points where the affected memory was being read, and the affected memory was no longer at the same location.  This testing was done on a VM, so some memory reads are not necessarily going to be visible to the debugger. Everything works perfectly on Vista (both my local machine and a Vista VM).  The access violation only occurs on XP. I'm using VB6 Version 8176, 6.0.8169
59807
How can I get crash data (stack traces at least) from my Android application? At least when working on my own device being retrieved by cable, but ideally from any instance of my application running on the wild so that I can improve it and make it more solid.
32438
I've been working on the Android SDK platform, and it is a little unclear how to save an application's state. So given this minor re-tooling of the 'Hello, Android' example:  package com.android.hello;  import android.app.Activity; import android.os.Bundle; import android.widget.TextView;  public class HelloAndroid extends Activity {    private TextView mTextView = null;    /** Called when the activity is first created. */   @Override   public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);      mTextView = new TextView(this);      if (savedInstanceState == null) {        mTextView.setText("Welcome to HelloAndroid!");     } else {        mTextView.setText("Welcome back.");     }      setContentView(mTextView);   } }   I thought it would be enough for the simplest case, but it always responds with the first message, no matter how I navigate away from the app.  I'm sure the solution is as simple as overriding onPause or something like that, but I've been poking away in the documentation for 30 minutes or so and haven't found anything obvious.
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;     }   }  } }
16290
This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through the resources here and use them to shape more specific questions. To browse all canonical questions and answers, navigate to the  tag. This question and answer is owned by the community! If you can improve it and make it more useful, you're welcome to edit it. I am building a trigger, a unit test, or other Apex code. I'm working with sObject records, and trying to access related record information. For example, I might have a structure like this: Account a = new Account(Name = 'Test'); insert a;  Opportunity o = new Opportunity(Name = 'Donation', AccountId = a.Id); insert o;  System.assertEquals(o.Account.Name, 'Test', 'Correct Account associated'); // Assertion fails!  Or, in a trigger, I might be aiming for something like this: trigger ContactTrigger on Contact (after insert) {     for (Contact c : Trigger.new) {         if (c.Account.Name == 'Test') {             // Take some action here         }      } }  Why doesn't this work? Why am I getting null values, or NullPointerExceptions?
120576
We are in the early stages of development of the official Stack Exchange Android app and we need your help with testing. To set a few expectations: there will be bugs, crashes, and missing features, all of which will be fixed in .    We are initially targeting Android devices running  (Android 4.1 or higher) starting with phones (up to ~5 inch) and eventually moving our way to tablets.    To register for alpha testing .  After you register we will send you an invite to a private Google community where you can find a link to download our app directly from the  store. The invitations will be sent out in waves, so if you don’t get an invite immediately, be patient.  Crash reports will be automatically reported back to us using . Bugs or feature requests should be reported here on meta and tagged . Please do not use the Google community to report bugs.  As always, we welcome your feedback and are committed to building the best mobile app possible for browsing the Stack Exchange sites.
112643
I have an issue with remote objects: I run the following code:  &lt;apex:remoteObjectModel name="Case" jsShorthand="case"                      fields="Subject,Id,CaseNumber,CreatedDate,Status,Description,IsClosed,Priority,Type"/&gt;      var cases = new SObjectModel.Case();     cases.retrieve({where: {IsClosed: {eq: false}}}     , function(error, records) {     });   and the error is:  Error occurred while performing RETRIEVE operation on sobject: Case with data: {where={IsClosed={eq=true}}} (MALFORMED_QUERY:  subject, createddate, id, casenumber, _cid FROM Case WHERE IsClosed =                                      ^ ERROR at Row:1:Column:76 line 1:76 no viable alternative at character '_')    Well, yesterday it was working ok. What can be wrong with this part?
117975
I've got a "Schroedinger's Cat" type of problem here -- my program (actually the test suite for my program, but a program nonetheless) is crashing, but only when built in release mode, and only when launched from the command line.  Through caveman debugging (ie, nasty printf() messages all over the place), I have determined the test method where the code is crashing, though unfortunately the actual crash seems to happen in some destructor, since the last trace messages I see are in other destructors which execute cleanly.  When I attempt to run this program inside of Visual Studio, it doesn't crash.  Same goes when launching from WinDbg.exe.  The crash only occurs when launching from the command line.  This is happening under Windows Vista, btw, and unfortunately I don't have access to an XP machine right now to test on.  It would be really nice if I could get Windows to print out a stack trace, or something other than simply terminating the program as if it had exited cleanly.  Does anyone have any advice as to how I could get some more meaningful information here and hopefully fix this bug?  Edit: The problem was indeed caused by an out-of-bounds array, .  Thanks everybody for your help in finding this problem!
89662
Whenever I click the icon on my desktop to get to Minecraft, the launcher loads as usual, like it should. But when I click the "Play" button, the launcher goes away, but then comes back saying this:  [17:15:14] [Client thread/INFO]: Setting user: kassidygallowway [17:15:14] [Client thread/INFO]: (Session ID is token:7b2075512917473abe32b04ffd11b2a4:ce288cc1399b4266a07c19cc48d47531) Exception in thread "Client thread" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1     at com.google.gson.Gson.fromJson(Gson.java:815)     at com.google.gson.Gson.fromJson(Gson.java:768)     at lu.b(SourceFile:151)     at lu.&lt;init&gt;(SourceFile:43)     at net.minecraft.server.MinecraftServer.&lt;init&gt;(SourceFile:155)     at bpp.&lt;init&gt;(SourceFile:41)     at avf.&lt;init&gt;(SourceFile:293)     at net.minecraft.client.main.Main.main(SourceFile:124) Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1     at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:338)     at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:79)     at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)     at com.google.gson.Gson.fromJson(Gson.java:803)     ... 7 more   I have no idea what this means (I dont know codes or anything like that). It does this over and over again, no matter how many times I press Play.