0

I have an app that processing some pdf files in background and suddenly it crashes with no 'caused by' description. Tried with real devices, new emulators, restarted pc and so on. enter image description here Never had something before and I don't know where to search for the root cause.

Edit: I found that problem was in a try/catch block

try {
val pdfReader = PdfReader(URL(it))
//process
pdfReader.close()
} catch(e: FileNotFoundException){
//process exception
}

So the problem was in wrong exception, when I switched to a more general exception, I could handle it and see error in logcat

try {
val pdfReader = PdfReader(URL(it))
//process
pdfReader.close()
} catch(e: Exception){
//process exception
}
Ax1
  • 17
  • 4

1 Answers1

0

If you are using iTextPdf it can sometimes throw NoClassDefFoundError for no reason as far as i have experienced. Maybe catching this Error instead of Exceptions could help you identify the problem. Like this:

try
{
  // do stuff
}
catch (Error err) //or NoClassDefFoundError
{
  System.err.println(err.getMessage());
}
Numan Karaaslan
  • 1,365
  • 1
  • 17
  • 25
  • This is not solution to my question, but it was a clue for me, the problem was in a try catch block, I will edit my question to provide solution. Thank you! – Ax1 Sep 09 '21 at 11:02
  • You should NEVER catch `Error`. https://stackoverflow.com/a/11018879/6296561 -- A NoClassDefFoundError is an indicator of a severe problem at compile time that you need to fix. Not catch, ignore, and pretend it doesn't exist. _Fix._ – Zoe Sep 09 '21 at 11:41
  • You are both right, an error is not meant to be caught and my solution was not a solution. It was a suggestion because i have had this kind of problem before. If there is a class not found error, you should really look into that library or the android os itself. – Numan Karaaslan Sep 09 '21 at 20:34