# Write error log on crash in libGDX?

I've been having problems building my game. I've built it successfully before, until I added the LuaJava.dll and LuaJava.jar files (so I can use Lua in my game).

Now, it just briefly opens with black screen and immediately closes. Even though it works just fine in Eclipse.

What I used to do before, was set my jar file in my assets and it would just work fine. But now, it refuses to work, and I have no idea what the error is.

Is there a function I can call to output the error into a log file?

• could you clarify what you mean by "set my jar file in my assets"? Jar files need to be added to the build path and should not be loaded as an asset. – spectacularbob Dec 15 '15 at 23:07

I don't know about writing an error log on crash, but all Android apps already log to the built-in logger. You just need an app like CatLog to view them.

Although verbose, you can usually filter by namespace (and see logs only related to your application). Eclipse does something similar with the built-in log viewer.

This is the only log viewer I used when I worked on my libGDX games.

• My project is a desktop project though. – GigaNova Dec 17 '15 at 20:16
• @GigaNova are you able to debug it with the Eclipse debugger? – ashes999 Dec 17 '15 at 20:20
• ofcourse, but I'm running a compiler Jar file. – GigaNova Dec 17 '15 at 21:17
• @GigaNova you should be able to set breakpoints and debug to the line that's terminating/failing. You should also be able to see some sort of exception (albeit maybe a runtime one) explaining why it's crashing. – ashes999 Dec 17 '15 at 22:35
• Again, it works completely fine in Eclipse, It's the compiled Jar that doesn't work. – GigaNova Dec 18 '15 at 7:58

## Solution 1

What I do to log errors is to surround my render() method with a try and catch block that catches the default Exception class. This writes a simple time-stamped log file. It can be implemented like this (Java 7+ Only):

@Override
public void render() {
try(BufferedWriter writer = new BufferedWriter(new FileWriter(new SimpleDateFormat("ddMMyyHHmmss").format() + ".log") {
//Code here
} catch(Exception e) {
writer.write("ERROR:\n");
writer.write(e.getMessage());
writer.close();
}
}


## Solution 2

You can run the program on the console using the java -jar {jarname}.jar command on the command line to see the error log.

Hope this helps! ~ Ammar Tarajia

P.S: On Windows, to navigate to the correct directory, just do the cd command then the folder. (Don't include the drive code!)