I’m reading a JSON response with Gson, which returns somtimes a NumberFormatException because an expected int value is set to an empty string. Now I’m wondering what’s the best way to handle this kind of exception. If the value is an empty string, the deserialization should be 0. Expected JS…
How to scan QRCode in android
I found a tutorial on how to scan a barcode. But in my application I have to scan a QR code. How can I a scan QR code in Android? Answer and in onActivityResult():
How to kill currently running task in android
I am trying to build a task killer type of app in android. I can show the list of currently running task using ActivityManager but facing problem in killing the task. Here is what i am doing to get the list of currently running task : It worked for me But now as I am trying to kill the task
Is it possible to assign numeric value to an enum in Java?
Is anything like this possible in Java? Can one assign custom numeric values to enum elements in Java? public enum EXIT_CODE { A=104, B=203; }
Java RMI can not connect to registry
I have an server process with internal registry (on an Amazon EC2 instance). The server starts correctly and the registry binds itself to port 1099. If I use netstat I can see that it is bound: tcp6 …
Printing the enum’s name
I’m using eclipse + Android SDK on Ubuntu. I would like to print the name of a sensor type device, there a a lot of them and I want to do it automatically. If I use a I print the (int) type, but I would like the name of the enum. How could I do that? Answer For enumerations, you
Testing Private method using mockito
How to test private method is called or not, and how to test private method using mockito? Answer You can’t do that with Mockito but you can use Powermock to extend Mockito and mock private methods. Powermock supports Mockito. Here’s an example.
Using Java NIO with Unix Domain sockets in non-blocking mode with selectors
Is there a way to use Unix Domain sockets with Java NIO? I want to use NIO so that I can use Selectors on it in a single thread. I had a look at junixsocket but it only seems to support normal Sockets not NIO channels that support selectors. Answer You can use the project jnr-unixsocket,(https://github.com/jn…
Fastest way to concatenate multiple strings
I’m working on a function that requires to concatenate multiple strings. Something like 200 – 500 strings. I’m currently using StringBuffer. I wanted to know if this is the fastest way to concatenate multiple strings. I need this method to be as efficient as possible. Answer The StringBuffer…
Why does setting the -Xmx too high sometimes cause the JVM to fail, even if there’s available RAM?
Basically we’ve noticed that on some computers setting the JVM option -Xmx (max heap size) sometimes cause the JVM to fail to initialize, even if there’s more than adequate RAM on the system. So for example, on a 4gb machine, we have -Xmx1024m which fails but -Xmx800m works. I could understand on …