1

我刚刚从 ADT 对一个正常工作的应用程序进行了清理,现在它崩溃了。以下是我所知道的...

这是主应用程序...

public class MainActivity extends Activity {
private GolferDBManager mydManager;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Go get the Known Golfers
    mydManager = new GolferDBManager(this);
    mydManager.openReadable();
    mydManager.retrieveGolfers();
    mydManager.close();

}

这是 GolferDBManager 类:

public class GolferDBManager {
public static final String DB_NAME = "golfgames";
public static final String DB_TABLE = "golfers";
public static final int DB_VERSION = 1;
private static final String CREATE_TABLE = "CREATE TABLE " + DB_TABLE + " (index INTEGER PRIMARY KEY, golfer_name TEXT, golfer_init TEXT, usga_index DOUBLE);";
private SQLHelper helper;
private SQLiteDatabase db;
private Context context;


public GolferDBManager(Context c){
    this.context = c;
    helper=new SQLHelper(c);
    this.db = helper.getWritableDatabase();
}
public class SQLHelper extends SQLiteOpenHelper {
    public SQLHelper(Context c){
        super(c, DB_NAME, null, DB_VERSION);
    }

它崩溃了

    this.db = helper.getWritableDatabase();

的线

        mydManager = new GolferDBManager(this);

2行进入主应用程序。

清理搞砸了数据库吗?

这是调试堆栈

Thread [<1> main] (Suspended (exception RuntimeException))  
<VM does not provide monitor information>   
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2211    
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2261 
ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 141    
ActivityThread$H.handleMessage(Message) line: 1256  
ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 137 
ActivityThread.main(String[]) line: 5103    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 525  
ZygoteInit$MethodAndArgsCaller.run() line: 737  
ZygoteInit.main(String[]) line: 553 
NativeStart.main(String[]) line: not available [native method]  

Logcat 说:

11-09 16:19:54.386: E/SQLiteLog(1184): (1) near "index": syntax error

谢谢。

4

1 回答 1

0

在定义数据库的字段时,我使用索引作为字段名

CREATE_TABLE= ...

. 不知道为什么它工作了一段时间 - 它不应该有。但是将其更改为另一个名称可以解决问题。

感谢您的关注。

ddk

于 2013-11-09T21:28:09.307 回答