所以就像标题说我的应用程序崩溃了因为我无法创建一个新表。
我已经尝试过了:
我使用糖orm版本1.5
我的代码: (清单)
<meta-data android:name="DATABASE" android:value="sugar_example.db" />
<meta-data android:name="VERSION" android:value="3" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.steinfluss.sugarormtest"/>
我的糖orm Objects类
import com.orm.SugarRecord;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.concurrent.atomic.AtomicReference;
public class Exercise extends SugarRecord{
private ArrayList<MuscleGroup> muscleGroups = new ArrayList<>();
private String name, comment;
private int exerciseId;
private ArrayList<TimeValuesPair> values = new ArrayList<>();
public Exercise(){
}
public ArrayList<MuscleGroup> getMuscleGroups() {
return muscleGroups;
}
public void setMuscleGroups(ArrayList<MuscleGroup> muscleGroups) {
this.muscleGroups = muscleGroups;
}
public int getExerciseId() {
return exerciseId;
}
public void setExerciseId(int exerciseId) {
this.exerciseId = exerciseId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public void addRow(Calendar dateCalendar, ArrayList<Double> arrayList){
TimeValuesPair timeValuesPair = new TimeValuesPair(arrayList, dateCalendar);
values.add(timeValuesPair);
}
public ArrayList<TimeValuesPair> getValues(){
return values;
}
public void setValues(ArrayList<TimeValuesPair> values) {
this.values = values;
}
}
错误:
01-12 17:30:14.195 17994-17994/com.steinfluss.fitnessplaner E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.steinfluss.fitnessplaner, PID: 17994
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.steinfluss.fitnessplaner/com.steinfluss.fitnessplaner.MuscleGroupExercisesActivity}: android.database.sqlite.SQLiteException: no such table: EXERCISE (code 1): , while compiling: SELECT * FROM EXERCISE
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.database.sqlite.SQLiteException: no such table: EXERCISE (code 1): , while compiling: SELECT * FROM EXERCISE
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1343)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1190)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1061)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1267)
at com.orm.SugarRecord.find(SugarRecord.java:201)
at com.orm.SugarRecord.listAll(SugarRecord.java:127)
at com.steinfluss.fitnessplaner.MuscleGroupExercisesActivity.onCreate(MuscleGroupExercisesActivity.java:43)
at android.app.Activity.performCreate(Activity.java:6998)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
01-12 17:30:14.197 17994-17994/com.steinfluss.fitnessplaner E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.steinfluss.fitnessplaner/com.steinfluss.fitnessplaner.MuscleGroupExercisesActivity}: android.database.sqlite.SQLiteException: no such table: EXERCISE (code 1): , while compiling: SELECT * FROM EXERCISE
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: android.database.sqlite.SQLiteException: no such table: EXERCISE (code 1): , while compiling: SELECT * FROM EXERCISE
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1343)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1190)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1061)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1267)
at com.orm.SugarRecord.find(SugarRecord.java:201)
at com.orm.SugarRecord.listAll(SugarRecord.java:127)
at com.steinfluss.fitnessplaner.MuscleGroupExercisesActivity.onCreate(MuscleGroupExercisesActivity.java:43)
at android.app.Activity.performCreate(Activity.java:6998)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6809)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
我的活动代码,它抛出:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_muscle_group_exercises);
SugarContext.init(getApplicationContext());
/*Exercise exercise = new Exercise();
exercise.setName("Exercise");
exercise.setComment("Comment");
exercise.save();*/
ArrayList<Exercise> exercises = new ArrayList<>();
exercises.addAll(Exercise.listAll(Exercise.class)); //throws here
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
overridePendingTransition(R.anim.transition_new_item_from_right_old, R.anim.transition_new_item_from_right_new);
Intent i = getIntent();
final String name = i.getStringExtra(RVMuscleGroupsAdapter.NAME);
//final int id = i.getIntExtra(RVMuscleGroupsAdapter.POSISTION,-1);
if (name != null){
this.setTitle(getApplicationContext().getString(R.string.exercises) + " " + getApplicationContext().getString(R.string.forMuscleGroup) + " " + name);
}
//init views
recyclerView = findViewById(R.id.recyclerViewExercises);
//init buttons - functionality
final RecyclerView.Adapter rvAdapter = updateRecyclerView();
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
createAddExerciseDialog(rvAdapter);
}
});
}
请求任何帮助。