Double clicking in my ListActivity force closes

Vzfhcxbd

New Member
This will first cause it's the first thing everyone wants.\[code\]04-07 17:27:19.597: W/dalvikvm(19636): threadid=1: thread exiting with uncaught exception (group=0x40019560)04-07 17:27:19.597: E/AndroidRuntime(19636): FATAL EXCEPTION: main04-07 17:27:19.597: E/AndroidRuntime(19636): java.lang.NullPointerException04-07 17:27:19.597: E/AndroidRuntime(19636): at com.Test.app.MainGamePanel.onTouchEvent(MainGamePanel.java:85)04-07 17:27:19.597: E/AndroidRuntime(19636): at android.view.View.dispatchTouchEvent(View.java:3920)04-07 17:27:19.597: E/AndroidRuntime(19636): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)04-07 17:27:19.597: E/AndroidRuntime(19636): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:869)04-07 17:27:19.597: E/AndroidRuntime(19636): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1775)04-07 17:27:19.597: E/AndroidRuntime(19636): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1162)04-07 17:27:19.597: E/AndroidRuntime(19636): at android.app.Activity.dispatchTouchEvent(Activity.java:2096)04-07 17:27:19.597: E/AndroidRuntime(19636): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1759)04-07 17:27:19.597: E/AndroidRuntime(19636): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2217)04-07 17:27:19.597: E/AndroidRuntime(19636): at android.view.ViewRoot.handleMessage(ViewRoot.java:1888)04-07 17:27:19.597: E/AndroidRuntime(19636): at android.os.Handler.dispatchMessage(Handler.java:99)04-07 17:27:19.597: E/AndroidRuntime(19636): at android.os.Looper.loop(Looper.java:130)04-07 17:27:19.597: E/AndroidRuntime(19636): at android.app.ActivityThread.main(ActivityThread.java:3694)04-07 17:27:19.597: E/AndroidRuntime(19636): at java.lang.reflect.Method.invokeNative(Native Method)04-07 17:27:19.597: E/AndroidRuntime(19636): at java.lang.reflect.Method.invoke(Method.java:507)04-07 17:27:19.597: E/AndroidRuntime(19636): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:895)04-07 17:27:19.597: E/AndroidRuntime(19636): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653)04-07 17:27:19.597: E/AndroidRuntime(19636): at dalvik.system.NativeStart.main(Native Method)\[/code\]Where it says MainGamePanel is confusing. You are brought to ListActivity from this onTouchEvent. By the time you make it to ListActivity the activity that uses MainGamePanel calls finish() inside it's onPause().If you just click on something in the ListActivity this doesn't even happen. This happens when you double click in ListActivity.I'm sure this has nothing to do with MainGamePanel, but all these exceptions seem to be elsewhere in the android system itself.My ListActivity is setup exactly like this. http://android-er.blogspot.com/2010/06/using-convertview-in-getview-to-make.htmlIs the android system causing this force close? What can I do to avoid this? Should I use something other than ListActivity?\[code\]public class ListActivity extends ListActivity { private String[] names = new String[] { "One", "Two", }; private int[] faces = new int[] { R.drawable.one, R.drawable.two, }; private Context mainContext; private boolean handledClick; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); ListAdapter adapter = new MyCustomAdapter(ListActivity.this, R.layout.list, names); handledClick = false; setListAdapter(adapter); } public class MyCustomAdapter extends ArrayAdapter<String> { public MyCustomAdapter(Context context, int textViewResourceId, String[] objects) { super(context, textViewResourceId, objects); mainContext = context; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); View row = inflater.inflate(R.layout.foodlist, parent, false); TextView label = (TextView)row.findViewById(R.id.listlabel); label.setText(names[position]); ImageView icon = (ImageView)row.findViewById(R.id.listicon); icon.setImageResource(faces[position]); return row; } } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); if (!handledClick){ handledClick = true; SharedPreferences prefs = getSharedPreferences("PREFS", 0); SharedPreferences.Editor editor = prefs.edit(); Object o = this.getListAdapter().getItem(position); String keyword = o.toString(); if (keyword.equals("One")) { int one = 1; editor.putInt("number", one); } else if (keyword.equals("Two")) { int two = 2; editor.putInt("number", two); } Intent intent = new Intent(mainContext, MainActivity.class); mainContext.startActivity(intent); } else { } }}\[/code\]This is the onTouchEvent in MainGamePanel\[code\]@Override public boolean onTouchEvent(MotionEvent event) { int touchedx = (int) event.getX(); int touchedy = (int) event.getY(); if (!handledClick){ handledClick = true; if (isBitmapTouched(button.getHeight(), button.getWidth(), touchedx, touchedy, button.getX(), button.getY())) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: Intent intent = new Intent(this.mainContext, ListActivity.class); this.mainContext.startActivity(intent); break; } handledClick = false; } } return true; }\[/code\]
 
Top