0

Hey I am new at android developing, and I am having a big problem with my application but I can't find the error, can someone help me?

I am getting a null pointer exeption.

MainActivity.java: http://www.codeshare.io/ywC71
ApiConnector.java: http://www.codeshare.io/u6FVk

Error: enter image description here

I don't know what I did wrong please help me, thanks, cheers.

1
  • Add you code in the question and not as link, if the link becomes invalid, question will also become invalid here Commented Mar 3, 2015 at 14:55

2 Answers 2

4

Your jsonArray object is null. Check its value where you are getting it from. And write your loop like this:

if(jsonArray != null){
    for(int i = 0; i < jsonArray.length ; i++)
         .....
Sign up to request clarification or add additional context in comments.

Comments

2

Your answer is given in the log files itself. If you chek thoroughly the line is given in your logcat,

"at net.competitiveworld.sqllasttry.MainActivity.setTextToTextView(MainActivity.java:32)"

So, line number 32 of your MainActivity has the issue. If you double click on the line in Logcat, it will lead you to that particular line,

"for(int i=0; i<jsonArray.length();i++){"

And in this line, there is only one object which can be null, 'jsonArray'. So when you are trying to get length() of a null object you are getting NullPointerException. You should add check the null as ZygoteInit mentioned. You can check with the URL/server why it is giving you null value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.