Advertisement
dermetfan

Understanding Stacktrace

Aug 11th, 2014
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. They're not really that complicated. It's always the same:
  2.  
  3. Exception in thread [thread name] [exception.toString()]
  4. at [class name].[method name]([file name]:[line where the exception occured])
  5. at [the same for the method that called the method in the previous line]
  6. at [and so on...]
  7.  
  8. Imagine it like this: An exception goes up in the methods where it occured like a bubble in water. Let's consider this piece of code:
  9.  
  10. package somePackage;
  11.  
  12. public class SomeClass {
  13.  
  14. public void firstMethod() {
  15. secondMethod();
  16. }
  17.  
  18. public void secondMethod() {
  19. thirdMethod();
  20. }
  21.  
  22. public void thirdMethod() {
  23. ((String) null).length(); // this would cause an exception
  24. }
  25.  
  26. }
  27.  
  28. The error report (stacktrace) if you call firstMethod() would be:
  29.  
  30. Exception in thread "main" java.lang.NullPointerException
  31. at somePackage.SomeClass.thirdMethod(SomeClass.java:14)
  32. at somePackage.SomeClass.secondMethod(SomeClass.java:10)
  33. at somePackage.SomeClass.firstMethod(SomeClass.java:6)
  34.  
  35. So the stacktrace tells you that a NullPointerException occured in thirdMethod() (line 14) of SomeClass, called by secondMethod() (line 10) of SomeClass which again was called by firstMethod() (line 6) of SomeClass.
  36. With this information you could go to the specified location in your code and see what could have been null (NullPointerException) in that line.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement