我在代码中没有任何错误,但是当我运行应用程序时它崩溃。这是一张日志图片。 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