Caught Throwable or Exception - null

A similar question was asked here twice and there was never an answer. Or the answer was: "This is impossible!" Sorry, this is probably too much:

try{ ... // the line that causes the error LinearLayout cell = (LinearLayout) inflater.inflate(R.layout.channels_list_cell, column); ... } catch(Throwable e){ Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); < breakpoint here! } 

At the breakpoint, e is null. How can I find a mistake please? Perhaps this is not a Java or Android issue, but an Eclipse debugger, which itself requires debugging. But what should I do besides changing to another IDE? Any ideas? Thanks in advance.

I tried Throwable, Exception, RuntimeException. The result is the same.

Trying to step over a breakpoint raises a NullPointerException, so e seems really null at that moment. Where can he be lost?

Edit: I bring my thanks to everyone and +1 to each respondent. It was an Eclipse error. After restarting the Eclipse, the Exception is no longer null, this is a normal RuntimeException: binary line of XML file # 15: you must specify the layout_width attribute. This would be another problem that needs to be solved, but this problem has been solved.

+4
source share
5 answers

If the exception you caught was a NullPointerException, the getMessage () method returns null, which can be misleading. I know that sometimes confused me!

In the debugger, you can select e and see the type and its fields. Also, another way to debug when things get very confusing is to go

  e.printStackTrace(); 

(note - I am not an Android guru, so if it works differently on Android, please comment!)

+2
source

Have you checked if e null is really or not? That is, adding something like if (e == null) Log.d("Exception is null") . Then I checked if the log statement was launched both during normal execution and during debugging. If the results are different from each other, this indicates a VM error (unlikely, but possible). If the message does not start anyway, this is more of a problem with the debugger.

A few thoughts on further actions that you can try to debug:

  • Try something like jdb and see if the same behavior works.

  • You can get a jdwp message dump between the debugger and the device and see what happens at that level. Perhaps use wirehark or tcpdump and grab the data going through the usb bus to the device.

  • You can try adding some debug statements to dalvik itself. For instance. take a copy of AOSP and create an emulator image, and then add some debugging instructions to dalvik to try and track what is going on.

  • You can try to execute some jdwp session script with the device

  • You can look at the bytecode (baksmali / dexdump / dedexer) to see something looks funny

+2
source

Android does not always throw an exception in Throwable . It actually manages all the exceptions from catLog . There you will find the details of your exceptions, even if your exception is null in the catch block.

You can easily access the catlog console from eclipse and filter to see only errors

UPDATE:

Your breakpoint must be inside the catch block.

+1
source

I know this question was published some time ago, and many times! Yesterday I fell into this trap, and I thought that I would publish what I found.

Definition of the problem: I used the following code

 public class myAppActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { -- lots of code -- } catch (Exception ex) { Log.e ("eTutorPrism Error", "Caught this exception " + ex); ex.printStackTrace(); } } } Symptom was that 'ex' was always null and resume will give NullPointerException, although the actual exception was an IllegalArgumentException in a call made into another class from the code above. 

RESEARCH: onCreate () code does not display an exception. instead, it shows exception = null.

Solution: DO NOT use too much processing in onCreate (). Move as much as possible to another thread. So I changed the code to look like this. voila, it works !!! I see the actual exception being displayed in Logcat.

 public class eTutorPrismAppActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); eTutorPrismTest myTest = new eTutorPrismTest (getApplicationContext()); myTest.start(); } } class eTutorPrismTest extends Thread { private Context m_AppContext = null; public eTutorPrismTest (Context appContext) { m_AppContext = appContext; } public void run () { -- lots of code that needs appContext -- } } 
+1
source

I'm not sure what causes this - it could be an Eclipse error, as mentioned earlier. Regardless of the reason, I found a workaround that seems to work. Hope this is helpful to others too.

After the exception is caught, assign it to another variable. The assigned variable must contain the correct exception in the debugger.

 SpecificException assignedVar = null; try { ... } catch (SpecificException exc) { assignedVar = exc; // <-- exc comes up null in the debugger, but assignedVar will be the correct object. } 

Hope this works for others as a workaround.

+1
source

Source: https://habr.com/ru/post/1391496/


All Articles