当我按下列表数据库项目的按钮时,我收到此错误。我的错在哪里? (当我看DDMS时,我在设备存储中看到 exDB 文件?)
VT_baglanti3类
public class VT_baglanti3 extends SQLiteOpenHelper {
// DataBase oluşturma
private static final String VT="exDB"; // veri tabanı adi
private static final Integer SURUM=1; // veri tabanı sürümü
public VT_baglanti3(Context c) {
super(c, VT, null, SURUM); // yukarıda tanımlanan değişkenleri parametre olarak verdik.
}
@Override
public void onCreate(SQLiteDatabase db) {
// tablo ekleme
db.execSQL("CREATE TABLE IF NOT EXISTS EMP_TABLE(_id integer primary key,E_NAME text,E_AGE text,E_DEPT text)");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
F_tarif_yaz类
public class F_tarif_yaz extends Fragment {
private View root;
Context con;
private VT_baglanti3 db;
private TextView txt;
Button bt;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
root = inflater.inflate(R.layout.tarif_yaz, container, false);
con=inflater.getContext();
db=new VT_baglanti3(con);
txt=(TextView)root.findViewById(R.id.txt);
bt=(Button)root.findViewById(R.id.bt);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Listele2();
}
});
return root;
}
private void Listele2(){
String sutunlar[]={"E_NAME","E_AGE","E_DEPT"};
SQLiteDatabase sldb2=db.getReadableDatabase();
Cursor cursor1=sldb2.query("exDB",sutunlar,null,null,null,null,null);
String tumbilgi="";
while (cursor1.moveToNext()){
String adbilgi=cursor1.getString(cursor1.getColumnIndex("E_NAME"));
String soyadbilgi=cursor1.getString(cursor1.getColumnIndex("E_AGE"));
String nobilgi=cursor1.getString(cursor1.getColumnIndex("E_DEPT"));
tumbilgi += adbilgi + " " + soyadbilgi + " " + nobilgi + " " + "\n";
}
txt.setText(tumbilgi);
}
}
错误日志
/com.yeni E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.yeni, PID: 1442
android.database.sqlite.SQLiteException: no such table: exDB (code 1): , while compiling: SELECT E_NAME, E_AGE, E_DEPT FROM exDB
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
at com.yeni.F_tarif_yaz.Listele2(F_tarif_yaz.java:50)
at com.yeni.F_tarif_yaz.access$000(F_tarif_yaz.java:15)
at com.yeni.F_tarif_yaz$1.onClick(F_tarif_yaz.java:39)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
错误行
com.yeni.F_tarif_yaz.Listele2(F_tarif_yaz.java:50) at Cursor cursor1=sldb2.query("exDB",sutunlar,null,null,null,null,null);
答案 0 :(得分:2)
DDMS我在设备存储中看到exDB文件
您的数据库中没有名为exDB
的 TABLE 。您的sqlite数据库的文件名完全不相关。