Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView setOnItemClickListener Exception
    primarykey
    data
    text
    <p>I'm working on an application which parses JSON data from a web service. This data is then stored within a list view and I am trying to enable the application to allow me to click an item within the list. In turn by clicking the item I am attempting to switch activities from the list view into a web view. However when I click on any item within the list the application states that an exception occurred, displays a message stating "Unfortunately [Application Name] has stopped.", and then exit the application. </p> <p>There are no other issues within the application other than this one. Therefore I would appreciate if anyone could help me to resolve this issue. I have supplied the full body of code from the main activity and the issues occurs within the try catch inside of onCreate, you can also download the application from here: <a href="http://bit.ly/17rePw0" rel="nofollow">http://bit.ly/17rePw0</a></p> <pre><code>public class MainActivity extends ListActivity { GPSManager gpsManager; ConnectionManager connectManager; LocationManager locationManager = null; LocationListener locationListener = null; AlertDialogManager alertManager = new AlertDialogManager(); private ProgressDialog progDialog; JSONParser parser = new JSONParser(); ArrayList&lt;HashMap&lt;String, String&gt;&gt; articleList; private String URL_ARTICLES = "http://api.wikilocation.org/articles?lat=56.4607208&amp;lng=-2.9680668&amp;format=json&amp;radius=100"; private static final String TAG_ARTICLES = "articles"; private static final String TAG_ID = "id"; private static final String TAG_LAT = "lat"; private static final String TAG_LNG = "lng"; private static final String TAG_NAME = "title"; private static final String TAG_URL = "url"; private static final String TAG_DISTANCE = "distance"; private static final int ARTICLE_LIMIT = 20; private static int ARTICLE_RADIUS = 100; JSONArray articles = null; double lat, lng; String latitude, longitude; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); articleList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); connectManager = new ConnectionManager(getApplicationContext()); gpsManager = new GPSManager(this); if(gpsManager.RetrieveLocation) { lat = gpsManager.RetrieveLatitude(); lng = gpsManager.RetrieveLongitude(); latitude = String.valueOf(lat); longitude = String.valueOf(lng); //URL_ARTICLES = "http://api.wikilocation.org/articles?lat=" + latitude + "&amp;lng=" + longitude + "&amp;format=json&amp;radius=100"; } else { gpsManager.showSettingsAlert(); } new LoadArticles().execute(); ListView listView = getListView(); try { listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; adapt, View view, int position, long id) { Intent intent = new Intent(MainActivity.this, WebActivity.class); startActivity(intent); } }); } catch(Exception e) { e.printStackTrace(); } } class LoadArticles extends AsyncTask&lt;String, String, String&gt; { protected void onPreExecute() { super.onPreExecute(); progDialog = new ProgressDialog(MainActivity.this); progDialog.setMessage("Loading Articles"); progDialog.setIndeterminate(false); progDialog.setCancelable(false); progDialog.show(); } protected String doInBackground(String... args) { List&lt;NameValuePair&gt;params = new ArrayList&lt;NameValuePair&gt;(); String json = parser.makeHttpRequest(URL_ARTICLES, "GET", params); Log.d("Articles JSON: ", "&gt; " + json); try { JSONObject jObj = new JSONObject(json); if(jObj != null) { articles = jObj.getJSONArray(TAG_ARTICLES); for(int i = 0; i &lt; articles.length(); i++) { JSONObject obj = articles.getJSONObject(i); String id = obj.getString(TAG_ID); String lat = obj.getString(TAG_LAT); String lng = obj.getString(TAG_LNG); String name = obj.getString(TAG_NAME); String address = obj.getString(TAG_URL); String distance = obj.getString(TAG_DISTANCE); HashMap&lt;String, String&gt;map = new HashMap&lt;String, String&gt;(); map.put(TAG_ID, id); map.put(TAG_LAT, lat); map.put(TAG_LNG, lng); map.put(TAG_NAME, name); map.put(TAG_URL, address); map.put(TAG_DISTANCE, distance); articleList.add(map); } } } catch(JSONException e) { e.printStackTrace(); } return null; } protected void onPostExecute(String file_url) { progDialog.dismiss(); runOnUiThread(new Runnable(){ public void run() { ListAdapter adapter = new SimpleAdapter(MainActivity.this, articleList, R.layout.list_item_articles, new String[] { TAG_ID, TAG_NAME, TAG_DISTANCE }, new int[]{ R.id.artcile_id, R.id.article_name, R.id.article_distance }); setListAdapter(adapter); } }); } } } </code></pre> <p>EDIT: Added LogCat stack trace.</p> <pre><code>08-03 23:44:02.407: W/dalvikvm(875): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 08-03 23:44:02.457: E/AndroidRuntime(875): FATAL EXCEPTION: main 08-03 23:44:02.457: E/AndroidRuntime(875): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.muc2013/com.android.muc2013.WebActivity}; have you declared this activity in your AndroidManifest.xml? 08-03 23:44:02.457: E/AndroidRuntime(875): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.app.Activity.startActivityForResult(Activity.java:3370) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.app.Activity.startActivityForResult(Activity.java:3331) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.app.Activity.startActivity(Activity.java:3566) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.app.Activity.startActivity(Activity.java:3534) 08-03 23:44:02.457: E/AndroidRuntime(875): at com.android.muc2013.MainActivity$1.onItemClick(MainActivity.java:99) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.widget.AdapterView.performItemClick(AdapterView.java:298) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.widget.AbsListView.performItemClick(AbsListView.java:1100) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.widget.AbsListView$1.run(AbsListView.java:3423) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.os.Handler.handleCallback(Handler.java:725) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.os.Handler.dispatchMessage(Handler.java:92) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.os.Looper.loop(Looper.java:137) 08-03 23:44:02.457: E/AndroidRuntime(875): at android.app.ActivityThread.main(ActivityThread.java:5041) 08-03 23:44:02.457: E/AndroidRuntime(875): at java.lang.reflect.Method.invokeNative(Native Method) 08-03 23:44:02.457: E/AndroidRuntime(875): at java.lang.reflect.Method.invoke(Method.java:511) 08-03 23:44:02.457: E/AndroidRuntime(875): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 08-03 23:44:02.457: E/AndroidRuntime(875): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 08-03 23:44:02.457: E/AndroidRuntime(875): at dalvik.system.NativeStart.main(Native Method) </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