sqlite的“表不存在”错误

| 我在android中访问数据库有问题。 首先,我创建了一个活动类,用于在数据库中创建表。 然后我从另一个地方叫那个活动。现在在编译时,我被卡在表不存在的错误所困扰。这是代码。 第一类是:
package bivin.hello;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;


public class main1 extends Activity {
      @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Intent i=new Intent();
        startActivity(i);
        SQLiteDatabase db;
        db=(SQLiteDatabase)openOrCreateDatabase(\"bivin.db\",  SQLiteDatabase.OPEN_READONLY,null);

        Cursor cur=db.query(\"emp\", null, null, null, null,null,null);
        db.beginTransaction();
        cur.moveToPosition(1);

      db.close();
呼叫活动是
package com.example.android.apis;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
public class createtable extends Activity
{
    public void onCreate(Bundle b)
    {
        super.onCreate(b);
        SQLiteDatabase db;
        db=openOrCreateDatabase(\"bivin.db\", SQLiteDatabase.CREATE_IF_NECESSARY, null);
        db.execSQL(\"create table emp(name text,password text;\");
        ContentValues c=new ContentValues();
        c.put(\"name\", \"Bivin\");
        c.put(\"password\", \"Ravindran\");

        db.insert(\"emp\",null,c);
        db.close();
        }
    }

    }
}
    
已邀请:
        它显而易见的createtable onCreate应该在main1的onCreate之前执行。该表是稍后创建的,因此会出现错误     
        您的数据类型错误,请使用varchar instread文本
SQLiteDatabase sampleDB = null;
String PhoneNumber;
String UserId;
Cursor c;
ArrayList ar=new ArrayList();
public void createDatabse(String DbName,Context context)
{

    sampleDB =  context.openOrCreateDatabase(DbName, context.MODE_WORLD_READABLE,null);

}

public void createUserIdTable(String Tablename,Context context)
{
    sampleDB.execSQL(\"CREATE TABLE IF NOT EXISTS \" +
            Tablename +
            \" (User_Id VARCHAR);\");

}

public void insertDataUser(String tableName,String User_Id)
{

     sampleDB.execSQL(\"INSERT INTO \" +
             tableName +
             \" Values (\'\"+User_Id+\"\');\");


}

public String GetUserData(Context context,String tablename)
{
            c = sampleDB.rawQuery(\"SELECT User_Id FROM \" +
                tablename +
                \"\", null);

            if(c!=null)
            {
                if(c.moveToFirst())
                {
                    do
                    {
                        UserId=c.getString(c.getColumnIndex(\"User_Id\"));

                    }while(c.moveToNext());



                    }   

                }       

            return UserId;
}

public void close()
{
    sampleDB.close();

}
    

要回复问题请先登录注册