1
    12-07 11:25:34.290: E/AndroidRuntime(9177): FATAL EXCEPTION: AsyncTask #2
12-07 11:25:34.290: E/AndroidRuntime(9177): java.lang.RuntimeException: An error occured while executing doInBackground()
12-07 11:25:34.290: E/AndroidRuntime(9177):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at java.lang.Thread.run(Thread.java:1096)
12-07 11:25:34.290: E/AndroidRuntime(9177): Caused by: java.lang.NullPointerException
12-07 11:25:34.290: E/AndroidRuntime(9177):     at com.UserLogin.Onaroundyou$getOnaroundyou.doInBackground(Onaroundyou.java:198)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at com.UserLogin.Onaroundyou$getOnaroundyou.doInBackground(Onaroundyou.java:1)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
12-07 11:25:34.290: E/AndroidRuntime(9177):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-07 11:25:34.290: E/AndroidRuntime(9177):     ... 4 more

When I'm trying to insert json array into my sqlite database i'm getting this Nullpoint exception error. on Lline 198 we are getting the value from jsonarray adding it to content values.

Till this line i'm getting values of json response i've printed key and value with in log. checked whether i'm getting any null values. But values are coming fine and i can able to see those in log. When my deguger entering into below line i'm gettng error. Please help once.

Evalues.put(InsertData.MyName,JSonArray1.getJSONObject(i).getString("MyName"));

Thanks in advance.

        private TextView tv;
        String str, Username, Eresult,Password;
        ProgressDialog dialog1;
        DatabaseHelper InsertEData;
        String attributeId ;
        Context mContext = this;
        SQLiteDatabase Edb ;
        JSONObject MyUserJsonObject;

    protected Void doInBackground(String... params) {
        // TODO Auto-generated method stub
                HttpClient httpclient = new DefaultHttpClient();
                // Dh.getWritableDatabase();

                String text1 = getString(R.string.site_name);
                String Url=text1+"Details";

                HttpPost httppost = new HttpPost(Url);


                try {
                HttpResponse responseGet = httpclient.execute(httppost);
                HttpEntity entity = responseGet.getEntity();
                if (entity != null) {
                    InputStream inputStreamResponse = entity.getContent();
                    Eresult = convertStreamToString(inputStreamResponse);
                    System.out.println(Eresult);
                    Edb= InsertEData.getWritableDatabase();

                    ContentValues Evalues = new ContentValues();
                    Evalues.clear();
                    MyUserJsonObject = new JSONObject(Eresult);

                    JSONObject menuObject = MyUserJsonObject.getJSONObject("UserDetails");
                    attributeId = menuObject.getString("login");

                    System.out.println("attribute  "+attributeId);
                    if (attributeId.equals("success")) {
                        JSONObject EObject = menuObject.getJSONObject("Ulist");
                        JSONArray EArray = EObject.getJSONArray("List");
                        System.out.println(EArray);
                        System.out.println(EArray.length());
                        for (int i = 0; i < EArray.length(); i++) {                             
                            //System.out.println(EArray.getJSONObject(0).getString("Name").toString());

                            Evalues.put(InsertEData.EName, EArray.getJSONObject(i).getString("MyName"));
                            Evalues.put(InsertEData.ELocation, EArray.getJSONObject(i).getString("Location"));
                            Evalues.put(InsertEData.ETotal, EArray.getJSONObject(i).getString("Total"));
                            Evalues.put(InsertEData.Eimage, EArray.getJSONObject(i).getString("Image"));
                            Edb.insert(InsertEData.ESLIST, null, Evalues );

                        }
                        Evalues.clear();

                        inputStreamResponse.close();

                    }else {
                        System.out.println("Unable to load page - " + responseGet.getStatusLine());
                    }
                }
                else
                    System.out.println("Entity Null");
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                System.out.println("Network Error");
                e.printStackTrace();
            }
            catch (IOException e) {
                e.printStackTrace();
            }

            return null;}

2 Answers 2

1

It seems like your array returns null value.

Please keep log and check and console.

1
  • But when i'm trying to print values it is coming in logcat System.out.println(JSonArray1.getJSONObject(i).getString("MyName")) Commented Dec 7, 2011 at 6:21
0

"Can anyone know why this happening."

The short answer is: because some object is null where it shouldn't be. Potential culprits could be InsertData, JSonArray1, or the result of JSonArray1.getJSONObject(i).

Without more details it's hard to pinpoint the exact cause. I suggest you breakpoint your code in order to find the issue.

5
  • Code added in question please check once. Commented Dec 7, 2011 at 7:35
  • I'm confused. Is it "MyName" or "Name"? I don't see the first anywhere in your code, whereas you claim that the code line causing the error does. Also, you seem to be mixing EventArray and EArray in the for loop - I don't see the former being declared/initialised anywhere. Same goes for a bunch of other variables. Finally, you're constantly printing out the first JSONObject in the loop, which makes little sense if you're interested in the actual content... Commented Dec 7, 2011 at 7:50
  • It is MyName, EArray and i'm just printing the first JSONObject to check whether the values are coming or not. here I just posted copied doinbackground method only. Commented Dec 7, 2011 at 8:08
  • Well the fact that the first value might be coming through doesn't mean anything for subsequent ones. It does indicate that EArray isn't null, so you can probably cross that one off your list. However, seen the nullpointer, it's quite likely that EArray.getJSONObject(i) will at some point return null, or that perhaps InsertEData.EName is null. Again, breakpoint your code and you'll have your answer in no-time. Or, as far as I'm concerned, put a sysout in the for loop for each item: System.out.println(InsertEData.EName + ", " + EArray.getJSONObject(i).getString("MyName"));. Commented Dec 7, 2011 at 9:00
  • MH Thanks for your suggestion i've followed that I was debugged the values response is getting correct from server.. But when the main problem is with this line..System.out.println(InsertEData.EName + ", " + EArray.getJSONObject(i).getString("MyName")); it is throwing the exception to threadpoolexecutor.java at setRejectedExecutionHandler function.. please help Commented Dec 9, 2011 at 11:56

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.