Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Sql数据库的空指针异常_Java_Android_Database_Sqlite - Fatal编程技术网

Java Sql数据库的空指针异常

Java Sql数据库的空指针异常,java,android,database,sqlite,Java,Android,Database,Sqlite,嘿,如果我想那么开始另一个活动我得到了这些例外 06-23 19:07:44.022: E/AndroidRuntime(1271): FATAL EXCEPTION: main 06-23 19:07:44.022: E/AndroidRuntime(1271): Process: food.manager, PID: 1271 06-23 19:07:44.022: E/AndroidRuntime(1271): java.lang.RuntimeException: Unable to s

嘿,如果我想那么开始另一个活动我得到了这些例外

06-23 19:07:44.022: E/AndroidRuntime(1271): FATAL EXCEPTION: main
06-23 19:07:44.022: E/AndroidRuntime(1271): Process: food.manager, PID: 1271
06-23 19:07:44.022: E/AndroidRuntime(1271): java.lang.RuntimeException: Unable to start       activity ComponentInfo{food.manager/food.manager.VerlaufEssen}: java.lang.NullPointerException
06-23 19:07:44.022: E/AndroidRuntime(1271):     at        .app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
   06-23 19:07:44.022: E/AndroidRuntime(1271):  at android.app.ActivityThread.access$800(ActivityThread.java:156)
  06-23 19:07:44.022: E/AndroidRuntime(1271):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at android.os.Handler.dispatchMessage(Handler.java:102)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at android.os.Looper.loop(Looper.java:157)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at android.app.ActivityThread.main(ActivityThread.java:5872)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at java.lang.reflect.Method.invokeNative(Native Method)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at java.lang.reflect.Method.invoke(Method.java:515)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at dalvik.system.NativeStart.main(Native Method)
 06-23 19:07:44.022: E/AndroidRuntime(1271): Caused by: java.lang.NullPointerException
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at food.manager.VerlaufEssen.populateListViewFromDB(VerlaufEssen.java:99)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at food.manager.VerlaufEssen.onCreate(VerlaufEssen.java:40)
06-23 19:07:44.022: E/AndroidRuntime(1271):     at android.app.Activity.performCreate(Activity.java:5312)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
 06-23 19:07:44.022: E/AndroidRuntime(1271):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552)
06-23 19:07:44.022: E/AndroidRuntime(1271):     ... 11 more
我想以创建Sql数据库时的模式打开

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verlauf_essen);
getActionBar().setDisplayHomeAsUpEnabled(true);
appContext = getApplicationContext();
openDB();
感谢您的帮助: 我的开放式方法:

myDb = new DBAdapter(this);
myDb.open();
我的数据库适配器:

    public DBAdapter(Context ctx) {
    this.context = ctx;
    myDBHelper = new DatabaseHelper(context);
}

// Open the database connection.
public DBAdapter open() {
    db = myDBHelper.getWritableDatabase();
    return this;
}

// Close the database connection.
public void close() {
    myDBHelper.close();
}
这是我的化蛹方法

private void populateListViewFromDB() {
Cursor cursor = myDb.getAllRows();

// Allow activity to manage lifetime of the cursor.
// DEPRECATED! Runs on the UI thread, OK for small/short queries.
startManagingCursor(cursor);

// Setup mapping from cursor to view fields:
String[] fromFieldNames = new String[] 
        {DBAdapter.KEY_KALO, DBAdapter.KEY_HYDRATE, DBAdapter.KEY_FAT, DBAdapter.KEY_PROTEIN ,DBAdapter.KEY_CAL};
int[] toViewIDs = new int[]
        {R.id.item_Kalorien,     R.id.item_KG_in_g,           R.id.item_F_in_g,     R.id.item_P_in_g,R.id.item_cal};

// Create adapter to may columns of the DB onto elemesnt in the UI.
SimpleCursorAdapter myCursorAdapter = 
        new SimpleCursorAdapter(
                this,       // Context
                R.layout.item_tagebuch, // Row layout template
                cursor,                 // cursor (set of DB records to map)
                fromFieldNames,         // DB Column names
                toViewIDs               // View IDs to put information in
                );

// Set the adapter for the list view
ListView myList = (ListView) findViewById(R.id.listViewTagebuch);
myList.setAdapter(myCursorAdapter);
GetallRows方法>

public Cursor getAllRows() {
    String where = null;
    Cursor c =  db.query(true, DATABASE_TABLE, ALL_KEYS, 
                        where, null, null, null, null, null);
    if (c != null) {
        c.moveToFirst();
    }
    return c;
}

食品经理是包裹的名称:你能发布你的openDB方法代码吗?我把它添加到我的问题中了。现在你能发布你的DBAdapter吗?你在哪里从DB调用populateListViewFromDB?还有,请把代码也贴出来:P对不起!