Skip to content
Advertisement

Method invocation ‘toString’ may produce ‘java.lang.NullPointerException’?

When I start the application, everything works normal, but when I press the button enter, it closes alone. I do not know what could be the problem I think this is it, could you please help me

I have this code

JavaScript

Method invocation ‘toString’ may produce ‘java.lan.NullPointerException’

Can you help me? Please

Advertisement

Answer

you can replace StringBuilder resul=null; with StringBuilder resul=new StringBuilder(); and in the try block, delete resul=new StringBuilder();.

if your connection catch any exception, the code resul=new StringBuilder(); will not be reached. Under this circumstance, the method will return null.toString(), This is why you got NullPointException.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement