在我的应用程序中,我有一个ListView,显示我设置的值(例如联系人列表)。当我点击任何值时,我的应用程序崩溃了。但是在代码中没有OnItemClickListener
甚至没有给我一个解决问题的理由。
logcat的:
10-08 20:14:07.453: E/AndroidRuntime(261): FATAL EXCEPTION: main
10-08 20:14:07.453: E/AndroidRuntime(261): java.lang.IllegalStateException: get field slot from row 0 col -1 failed
10-08 20:14:07.453: E/AndroidRuntime(261): at android.database.CursorWindow.getString_native(Native Method)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.database.CursorWindow.getString(CursorWindow.java:329)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
10-08 20:14:07.453: E/AndroidRuntime(261): at com.example.mensagem.Mensagenssalvas$1.onItemClick(Mensagenssalvas.java:59)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.widget.ListView.performItemClick(ListView.java:3382)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.os.Handler.handleCallback(Handler.java:587)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.os.Handler.dispatchMessage(Handler.java:92)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.os.Looper.loop(Looper.java:123)
10-08 20:14:07.453: E/AndroidRuntime(261): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-08 20:14:07.453: E/AndroidRuntime(261): at java.lang.reflect.Method.invokeNative(Native Method)
10-08 20:14:07.453: E/AndroidRuntime(261): at java.lang.reflect.Method.invoke(Method.java:521)
10-08 20:14:07.453: E/AndroidRuntime(261): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-08 20:14:07.453: E/AndroidRuntime(261): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-08 20:14:07.453: E/AndroidRuntime(261): at dalvik.system.NativeStart.main(Native Method)
我的.java代码:(不包含OnItemClickListener
)
public class Mensagenssalvas extends Activity {
public SQLiteDatabase db;
ArrayList<String> list = null;
Cursor c;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mensagenssalvas);
db = openOrCreateDatabase("banco.db", Context.MODE_WORLD_WRITEABLE, null);
Mensagens();
}
private void Mensagens() {
// TODO Auto-generated method stub
ListView user = (ListView) findViewById(R.id.lvMensagens);
String[] campos = new String[] {"mensagenssalvas", "mensagemsalva"};
list = new ArrayList<String>();
c = db.query( "mensagens", campos, null, null, null, null, null);
c.moveToFirst();
if(c.getCount() > 0) {
while(true) {
list.add(c.getString(c.getColumnIndex("mensagenssalvas")).toString());
if(!c.moveToNext()) break;
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, list);
user.setAdapter(adapter);
}
}
如果我的代码中甚至没有OnItemClickListener
,为什么会显示错误?