Note that there are some explanatory texts on larger screens.

plurals
  1. POApplication getting force stop
    primarykey
    data
    text
    <p>I have an activity in which i am trying to make a web service call for a url and display the json response into the activity, but my app is getting force stop as soon as i go on that activity.</p> <p>My RedemptionActivity is like this:</p> <pre><code> public class RedemptionActivity extends Activity { ListView redemptionListView; RedemptionListAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.redemption); redemptionListView = (ListView) findViewById(R.id.redemptionListView); if (SnapDineCommon.getInstance(this).isNetworkAvailable()) { new RedemptionResultAsyncTask(this).execute(); } else Toast.makeText(this, getString(R.string.check_network), Toast.LENGTH_SHORT).show(); } public class RedemptionResultAsyncTask extends AsyncTask&lt;String, Void, Boolean&gt; { Context context; ProgressDialog progressDialog; RedemptionResultResponse redemptionResultResponse; public RedemptionResultAsyncTask(Context context) { this.context = context; } protected void onPreExecute() { progressDialog = new ProgressDialog(context); progressDialog.setMessage("Loading..."); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); progressDialog.show(); } @Override protected Boolean doInBackground(String... params) { // TODO Auto-generated method stub try { Gson gson = new Gson(); RestWebServiceClient client = new RestWebServiceClient( SnapDineCommon.getInstance(this.context).SiteUrl + "getRedemptionData", this.context); client.AddParam("mobile_number", SnapDineCommon.getInstance(context) .getLoggedinMobileNumber()); client.Execute(RequestMethod.GET); String response = client.getResponse(); if (response == null) return false; else { redemptionResultResponse = gson.fromJson(response, RedemptionResultResponse.class); if (redemptionResultResponse == null) return false; else return true; } } catch (Exception e) { return false; } } @Override protected void onPostExecute(Boolean result) { progressDialog.dismiss(); progressDialog = null; if (result) { if (redemptionResultResponse.Success) { if (redemptionResultResponse.getSearchResult().size() &gt; 0) { //throwing null pointer exception adapter = new RedemptionListAdapter(context, R.layout.searchresult_row, redemptionResultResponse.getSearchResult()); redemptionListView.setAdapter(adapter); } else { Intent intent = new Intent(context, GenericOkDialogActivity.class); startActivity(intent); } } else { Toast.makeText(context, redemptionResultResponse.errorMessage, Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(context, "An error occured. Please try later.", Toast.LENGTH_SHORT).show(); } } } } </code></pre> <p>and logcat show following errors:</p> <pre><code> 04-10 14:04:21.545: E/AndroidRuntime(6798): FATAL EXCEPTION: main 04-10 14:04:21.545: E/AndroidRuntime(6798): java.lang.NullPointerException 04-10 14:04:21.545: E/AndroidRuntime(6798): at com.JustDine.GUI.RedemptionActivity$RedemptionResultAsyncTask.onPostExecute(RedemptionActivity.java:101) 04-10 14:04:21.545: E/AndroidRuntime(6798): at com.JustDine.GUI.RedemptionActivity$RedemptionResultAsyncTask.onPostExecute(RedemptionActivity.java:1) 04-10 14:04:21.545: E/AndroidRuntime(6798): at android.os.AsyncTask.finish(AsyncTask.java:417) 04-10 14:04:21.545: E/AndroidRuntime(6798): at android.os.AsyncTask.access$300(AsyncTask.java:127) 04-10 14:04:21.545: E/AndroidRuntime(6798): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429) 04-10 14:04:21.545: E/AndroidRuntime(6798): at android.os.Handler.dispatchMessage(Handler.java:99) 04-10 14:04:21.545: E/AndroidRuntime(6798): at android.os.Looper.loop(Looper.java:123) 04-10 14:04:21.545: E/AndroidRuntime(6798): at android.app.ActivityThread.main(ActivityThread.java:4627) 04-10 14:04:21.545: E/AndroidRuntime(6798): at java.lang.reflect.Method.invokeNative(Native Method) 04-10 14:04:21.545: E/AndroidRuntime(6798): at java.lang.reflect.Method.invoke(Method.java:521) 04-10 14:04:21.545: E/AndroidRuntime(6798): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876) 04-10 14:04:21.545: E/AndroidRuntime(6798): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634) 04-10 14:04:21.545: E/AndroidRuntime(6798): at dalvik.system.NativeStart.main(Native Method) 04-10 14:04:21.555: W/ActivityManager(124): Force finishing activity com.JustDine.GUI/.RedemptionActivity 04-10 14:04:21.555: W/AppErrorDialog(124): xjzb001 AppErrorDialog setLongMsg=java.lang.NullPointerException </code></pre> <p>I am unable to figure out why it is closing unexpectedly. Please help, why <code>"redemptionResultResponse.getSearchResult().size()"</code> is null, i have confirmed that redemptionResultResponse is not null..?????</p> <p><strong>Updated: here is what i have in RedemptionResultResponse:</strong></p> <pre><code> @SerializedName("Success") public boolean Success; @SerializedName("GetSearchResult") private List&lt;SearchResult&gt; getSearchResult; @SerializedName("errorMessage") public String errorMessage; @SerializedName("Tag") public String Tag; public List&lt;SearchResult&gt; getSearchResult() { return getSearchResult; } public void setSearchResult(List&lt;SearchResult&gt; getSearchResult) { this.getSearchResult = getSearchResult; } </code></pre> <p><strong>Updated XML</strong></p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LoginScreen" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#f0f0f0" android:orientation="vertical" &gt; &lt;RelativeLayout android:id="@+id/realtiveLayout1" android:layout_width="fill_parent" android:layout_height="44dp" android:background="#ffffff" &gt; &lt;ImageButton android:id="@+id/ibSearchResultsBack" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerInParent="true" android:layout_marginLeft="5dip" android:background="@drawable/backbtn" /&gt; &lt;TextView android:id="@+id/Title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Search Result" android:textColor="#FF0000" android:textSize="22sp" android:textStyle="bold" /&gt; &lt;LinearLayout android:id="@+id/settingLayout" android:layout_width="40dp" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:gravity="center" &gt; &lt;ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/settingicon" /&gt; &lt;/LinearLayout&gt; &lt;/RelativeLayout&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="5dp" android:background="@drawable/light_red_gradient" /&gt; &lt;EditText android:id="@+id/editText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Search.." android:singleLine="true" /&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="8" &gt; &lt;ListView android:id="@+id/redemptionListView" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="15dp" android:background="@drawable/light_red_gradient" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload