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;}