Eclipse Android"没有这样的专栏"错误

时间:2014-10-10 00:15:17

标签: java android eclipse sqlite

我正在为学校项目开发一个Android应用程序,当Eclipse调用代码来咨询数据库时会抛出这个错误:

     D/dalvikvm(2011): Not late-enabling CheckJNI (already on)
     I/SQLite(2011): Inicio de aplicación SQLite
     I/SQLite(2011): Aplicación SQLite creada correctamente :)  
     I/Choreographer(2011): Skipped 61 frames!  The application may be doing too much work on its main thread.
     I/Choreographer(2011): Skipped 69 frames!  The application may be doing too much work on its main thread.
     D/gralloc_goldfish(2011): Emulator without GPU emulation detected.
     E/SQLiteLog(2011): (1) no such column: significado
     D/AndroidRuntime(2011): Shutting down VM
     W/dalvikvm(2011): threadid=1: thread exiting with uncaught exception (group=0xb1d5eb20)
     E/AndroidRuntime(2011): FATAL EXCEPTION: main
     E/AndroidRuntime(2011): Process: com.tutorial.pasanaku, PID: 2011
     E/AndroidRuntime(2011): android.database.sqlite.SQLiteException: no such column: significado (code 1): , while compiling: SELECT significado FROM mi_tabla WHERE palabra=casa
     E/AndroidRuntime(2011):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
     E/AndroidRuntime(2011):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
     E/AndroidRuntime(2011):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
     E/AndroidRuntime(2011):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
     E/AndroidRuntime(2011):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
     E/AndroidRuntime(2011):    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
     E/AndroidRuntime(2011):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
     E/AndroidRuntime(2011):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
     E/AndroidRuntime(2011):    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
     E/AndroidRuntime(2011):    at com.tutorial.pasanaku.DataBaseHelper.consulta(DataBaseHelper.java:145)
     E/AndroidRuntime(2011):    at com.tutorial.pasanaku.AlfaActivity$1.onClick(AlfaActivity.java:52)
     E/AndroidRuntime(2011):    at android.view.View.performClick(View.java:4438)
     E/AndroidRuntime(2011):    at android.view.View$PerformClick.run(View.java:18422)
     E/AndroidRuntime(2011):    at android.os.Handler.handleCallback(Handler.java:733)
     E/AndroidRuntime(2011):    at android.os.Handler.dispatchMessage(Handler.java:95)
     E/AndroidRuntime(2011):    at android.os.Looper.loop(Looper.java:136)
     E/AndroidRuntime(2011):    at android.app.ActivityThread.main(ActivityThread.java:5017)
     E/AndroidRuntime(2011):    at java.lang.reflect.Method.invokeNative(Native Method)
     E/AndroidRuntime(2011):    at java.lang.reflect.Method.invoke(Method.java:515)
     E/AndroidRuntime(2011):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
     E/AndroidRuntime(2011):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
     E/AndroidRuntime(2011):    at dalvik.system.NativeStart.main(Native Method)
     I/Process(2011): Sending signal. PID: 2011 SIG: 9 

以下是加载现有数据库的代码。它位于“DataBaseHelper”类中。

public class DataBaseHelper extends SQLiteOpenHelper{

//The Android's default system path of your application database.
private static String DB_PATH = "/data/data/com.tutorial.pasanaku/databases/";

private static String DB_NAME = "dbTest";

private SQLiteDatabase myDataBase; 

private final Context myContext;

/**
 * Constructor
 * Takes and keeps a reference of the passed context in order to access to the application assets and resources.
 * @param context
 */
public DataBaseHelper(Context context) {

    super(context, DB_NAME, null, 1);
    this.myContext = context;
}   

“搜索”按钮的代码

    button1.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
             //Intent intent = new Intent(AlfaActivity.this, Activity.class);
             //startActivity(intent);
              final String palabra;
              final String mostrar;
              palabra=editText1.getText().toString();
              mostrar=databasehelper.consulta(palabra);
              textview2.setText(mostrar);
          }

我认为问题在于我没有将数据库放在正确的路径中。我把它放在“assets”文件夹中。这是错的吗?

1 个答案:

答案 0 :(得分:0)

通常,您不需要为数据库定义路径。 Android在/data/data/com.yourappname/databases/databasename

下创建数据库

如果您需要教程,doc会帮助您

此外,如果您使用的是eclipse,sqlitebrowser插件将帮助您直接查看数据库。 (您需要具有在真实设备上书写和阅读的权限。如果您使用的是真实设备,answer将帮助您设置权限)