我在代碼中沒有任何錯誤,但是當我運行應用程序時它崩潰。這是一張日誌圖片。 http://postimg.org/image/bbcovjovn/我無法弄清楚代碼中有什麼問題。Android應用程序在啓動運行時崩潰異常
MyBowlingScoresApplication.java
import java.util.ArrayList;
import android.app.Application;
import android.database.sqlite.SQLiteDatabase;
public class MyBowlingScoresApplication extends Application {
private ArrayList<BowlingScores> allBowlingScores;
private SQLiteDatabase bowlingScoresDB;
@Override
public void onCreate() {
super.onCreate();
BowlingScoresDatabaseHelper databaseHelper1 = new BowlingScoresDatabaseHelper(this);
bowlingScoresDB = databaseHelper1.getWritableDatabase();
//TODO get the data out of the database
allBowlingScores = new ArrayList<BowlingScores>();
}
public void addBowlingScores(BowlingScores bowlingScores){
assert bowlingScores != null;
allBowlingScores.add(bowlingScores);
}
public ArrayList<BowlingScores> getAllBowlingScores() {
return allBowlingScores;
}
private void setAllBowlingScores(ArrayList<BowlingScores> allBowlingScores) {
this.allBowlingScores = allBowlingScores;
}
}
BowlingScoresDatabaseHelper.java
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class BowlingScoresDatabaseHelper extends SQLiteOpenHelper {
public static final int DB_VERSION = 1;
public static final String DB_NAME = "MyBowlingScores.SQLite";
public static String BOWLING_SCORES_TABLE="BowlingScoresTable";
public static String RECORD_ID="ID";
public static String DATE = "Date";
public static String GAME1 = "Game1";
public static String GAME2 = "Game2";
public static String GAME3 = "Game3";
public BowlingScoresDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase bowlingScoresDB) {
String sqlStatement = "create table " + BOWLING_SCORES_TABLE
+ " ("
+ RECORD_ID + " integer primary key autoincrement not null,"
+ DATE + " integer,"
+ GAME1 + " integer,"
+ GAME2 + " integer,"
+ GAME3 + " integer,"
+ ");";
Log.d("Bowling Database", sqlStatement);
bowlingScoresDB.execSQL(sqlStatement);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
}
發表您的SQLite數據庫的輔助類 – Elltz 2014-10-18 17:31:11
您已在數據庫創建粘貼兩個類相同......請發表您的BowlingScoresDatabaseHelper類 – Jamil 2014-10-18 17:31:29
請發表您的logcat(不是圖片,而是實際的logcat) – 323go 2014-10-18 17:32:14