Android 我无法将数据从数据库获取到视图类。当我运行我的案例时,它意外关闭
以下是日志cat中的错误:Android 我无法将数据从数据库获取到视图类。当我运行我的案例时,它意外关闭,android,Android,以下是日志cat中的错误: 10-19 03:18:31.339: D/gralloc_goldfish(1440): Emulator without GPU emulation detected. 10-19 03:20:18.739: I/Choreographer(1440): Skipped 105 frames! The application may be doing too much work on its main thread. 10-19 03:20:19.429: I/
10-19 03:18:31.339: D/gralloc_goldfish(1440): Emulator without GPU emulation detected.
10-19 03:20:18.739: I/Choreographer(1440): Skipped 105 frames! The application may be doing too much work on its main thread.
10-19 03:20:19.429: I/Choreographer(1440): Skipped 333 frames! The application may be doing too much work on its main thread.
10-19 03:20:19.629: D/AndroidRuntime(1440): Shutting down VM
10-19 03:20:19.629: W/dalvikvm(1440): threadid=1: thread exiting with uncaught exception (group=0xb2ad6ba8)
10-19 03:20:19.799: E/AndroidRuntime(1440): FATAL EXCEPTION: main
10-19 03:20:19.799: E/AndroidRuntime(1440): Process: com.example.first, PID: 1440
10-19 03:20:19.799: E/AndroidRuntime(1440): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.first/com.example.first.ViewThought}: java.lang.NullPointerException
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.os.Handler.dispatchMessage(Handler.java:102)
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.os.Looper.loop(Looper.java:136)
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.app.ActivityThread.main(ActivityThread.java:5017)
10-19 03:20:19.799: E/AndroidRuntime(1440): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 03:20:19.799: E/AndroidRuntime(1440): at java.lang.reflect.Method.invoke(Method.java:515)
10-19 03:20:19.799: E/AndroidRuntime(1440): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
10-19 03:20:19.799: E/AndroidRuntime(1440): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10-19 03:20:19.799: E/AndroidRuntime(1440): at dalvik.system.NativeStart.main(Native Method)
10-19 03:20:19.799: E/AndroidRuntime(1440): Caused by: java.lang.NullPointerException
10-19 03:20:19.799: E/AndroidRuntime(1440): at com.example.first.ThoughtManager.getAllThoughts(ThoughtManager.java:83)
10-19 03:20:19.799: E/AndroidRuntime(1440): at com.example.first.ViewThought.onCreate(ViewThought.java:30)
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.app.Activity.performCreate(Activity.java:5231)
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-19 03:20:19.799: E/AndroidRuntime(1440): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
10-19 03:20:19.799: E/AndroidRuntime(1440): ... 11 more
10-19 03:25:20.079: I/Process(1440): Sending signal. PID: 1440 SIG: 9
当我在运行代码后尝试打开视图xml时,它会停止。我的代码有什么问题?请帮帮我
CRUD操作类:这里有所有的操作,比如插入、删除、更新等
这是my view类,其中包含查看数据的代码:
import java.util.ArrayList;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ViewThought extends ListActivity {
ThoughtManager manager;
ArrayList<Thought>allthoughts;
ArrayList<String>allTitles;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
manager=new ThoughtManager(this);
allTitles=new ArrayList<String>();
allthoughts=manager.getAllThoughts();
//getting all titles
for(Thought thought:allthoughts){
allTitles.add(thought.getTitle());
}
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, allTitles));
listView=getListView();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
这是我用来查看数据的xml:
import java.util.ArrayList;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ViewThought extends ListActivity {
ThoughtManager manager;
ArrayList<Thought>allthoughts;
ArrayList<String>allTitles;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
manager=new ThoughtManager(this);
allTitles=new ArrayList<String>();
allthoughts=manager.getAllThoughts();
//getting all titles
for(Thought thought:allthoughts){
allTitles.add(thought.getTitle());
}
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, allTitles));
listView=getListView();
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
错误是由于第83行com.example.first.ThoughtManager.getAllThoughtsThoughtManager.java:83处的NullPointerException导致的。您能标记它吗?公共数组列表getAllThoughts{cursor=db.queryThroughtDBHelper.TABLE_NAME,columns,null,null,null,null,null;iTitle=cursor.getColumnIndexThoughtDbHelper.TITLE;iDetail=cursor.getColumnIndexThoughtDbHelper.DETAIL;iTime=cursor.getColumnIndexThoughtDbHelper.TIME;iDate=cursor.getColumnIndexThoughtDbHelper.DATE;iAson=cursor.getColumnIndexThoughtDbHelper.REASON;icomment=cursor.getColumnIndexThoughtDbHelper.COMMENT;这是第83someone行中的代码。请帮助我..!!公共数组列表getAllThinks{cursor=db.queryThroughtDbHelper.TABLE_NAME,columns,null,null,null,null,null,null;