• Register
0 votes

Problem :

I am trying to learn Android programming also I am trying to develop a very basic weather app. My code works perfectly if I try to enter any valid city name. But I want to use the toast and it shows me the error and also to the user when a name is not valid. And I am very worried as this is resulting in the crash, I also tried to remove the toast logic, but still my app is crashing.

Below is the error message :

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116) at org.json.JSONTokener.nextValue(JSONTokener.java:94) at org.json.JSONObject.

How can I fix the above error?

2.3k points

1 Answer

0 votes

Solution :

Today while going through the posts I came across your question.

Android Programming is very easy don’t loose hope.

The solution for your problem is very simple.

It seems the exception is occurring in your doInBackground() and so it is going to return you the null. You can very easily fix this as follows

protected void onPostExecute(String str) {
    // You can do you work here on success
     // If you get null response or Exception occur 

Hope it helps you in resolving your error.

5k points

Related questions

0 votes
1 answer 72 views
Problem : While executing Android code getting below error java.lang.illegalstateexception could not execute method of the activity
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 105 views
Problem : I am getting bellow error while learning android and trying to make a semi-useful app. java.lang.illegalstateexception: could not execute method for android:onclick
asked Oct 19, 2019 peterlaw 6.9k points
1 vote
1 answer 81 views
Problem : I am very new to Apex Programming. I am trying to learn Apex using the tutorials available online. I am trying to write Apex Code. I want to set my RecordType.Name in a test class but my class gives me the below message:  "System.NullPointerException: ... : line 45, column 3 External entry point". I am completely stuck with above error. I need help in fixing above Apex related error.
asked May 16 Martin K 6.6k points