我已經借了魏萌李的「開頭的Android應用開發」下面的代碼:Android的教程錯誤
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter {
private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "MyDB";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE =
"create table contacts (_id integer primary key autoincrement, "
+ "name text not null, email text not null);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter (Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
try {
db.execSQL(DATABASE_CREATE);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS contacts");
onCreate(db);
}
}
}
還有更精彩的,但我試圖簡化。
我收到以下錯誤:
描述資源路徑位置類型
令牌 「),」 語法錯誤,{預期此令牌DBAdapter.java
末後的onUpgrade
語法錯誤,插入「}」以完成ClassBody DBAdapter.java
語法錯誤,插入 「}」 在
onCreate
末我是新來的Android完成ClassBody DBAdapter.java
的應用,因此可能有人請幫助我理解這些消息?
這裏是Eclipse是顯示:
你試過插入「}」嗎? –
它看起來十字是灰色的,所以錯誤被刪除?嘗試清潔,並建立 –
我需要點擊保存按鈕來更新我所有的faffing編輯! – John