Android 无法再次打开活动
在我的应用程序中,当我启动应用程序时,第一次一切正常,我可以在活动之间导航,但当返回到第一个活动(MainActivity)并尝试转到第二个活动时,我的应用程序崩溃了,我不知道为什么 在主要活动中:Android 无法再次打开活动,android,database,android-activity,Android,Database,Android Activity,在我的应用程序中,当我启动应用程序时,第一次一切正常,我可以在活动之间导航,但当返回到第一个活动(MainActivity)并尝试转到第二个活动时,我的应用程序崩溃了,我不知道为什么 在主要活动中: img_khayam.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(Main
img_khayam.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(MainActivity.this,KhayamSeason.class);
MainActivity.this.startActivity(intent);
}
});
在第二项活动中(哈亚姆季节):
正如我第一次说的,当我在MainActivity和SecondActivity(KhayamSeason)之间导航时没有问题,但当我按下back按钮并重试时,我的应用程序将崩溃。崩溃后,当我查看Logcat时,它会将我引用到以下代码行:
Name[i] = db.Show_Season("khayam", i);
Id[i] = db.get_id2("khayam", i, 0);
但是如果这两条线有问题为什么第一次工作得很好?!
我的应用程序实际上是为了在第二个活动中显示哈亚姆的诗歌季节列表,名字保存在SQLite数据库中,表格名为“哈亚姆”,我的第一个字段是“ID”,第二个是“名字”,第三个是“文本”
我的问题在哪里?
或者如何设置第二个活动的默认值?因为我认为在按下“后退”按钮后会保留一些数据。最后,我通过关闭光标在数据库类中进行更改来解决我的问题:
public String get_id2(String table,int field, int col){
Cursor Cursor=null;
try {
Cursor = mydb.rawQuery("SELECT * FROM "+table+" group by ID", null);
Cursor.moveToPosition(field);
String s = Cursor.getString(col);
return s ;
} catch (Exception e) {
} finally {
if(Cursor!= null){
Cursor.close();
}
}
return null ;
}
public Integer Count_field(String table){
Cursor cu=null;
int i;
try {
cu = mydb.rawQuery("SELECT * FROM "+table+" group by ID", null);
i = cu.getCount();
return i;
} catch (Exception e) {
} finally {
if(cu!= null){
cu.close();
}
}
return null ;
}
public String Show_Season(String table , int row){
Cursor Cursor=null;
try {
Cursor = mydb.rawQuery("SELECT * FROM "+table+" group by ID", null);
Cursor.moveToPosition(row);
String s = Cursor.getString(1);
return s ;
} catch (Exception e) {
} finally {
if(Cursor!= null){
Cursor.close();
}
}
return null ;
}
崩溃>没有Logcat发布??Logcat只是告诉我错误在哪里“我有错误,但Logcat只告诉我错误,为什么我有错误时需要知道错误?”->你没有任何意义…我不知道如何告诉你,但我的问题是为什么第一次一切都很好,但第二次不行?但如果这两条线有问题,为什么第一次一切都很好确切地说,为什么你应该发布日志,因为它会告诉你为什么,是什么导致了它
Name[i] = db.Show_Season("khayam", i);
Id[i] = db.get_id2("khayam", i, 0);
public String get_id2(String table,int field, int col){
Cursor Cursor=null;
try {
Cursor = mydb.rawQuery("SELECT * FROM "+table+" group by ID", null);
Cursor.moveToPosition(field);
String s = Cursor.getString(col);
return s ;
} catch (Exception e) {
} finally {
if(Cursor!= null){
Cursor.close();
}
}
return null ;
}
public Integer Count_field(String table){
Cursor cu=null;
int i;
try {
cu = mydb.rawQuery("SELECT * FROM "+table+" group by ID", null);
i = cu.getCount();
return i;
} catch (Exception e) {
} finally {
if(cu!= null){
cu.close();
}
}
return null ;
}
public String Show_Season(String table , int row){
Cursor Cursor=null;
try {
Cursor = mydb.rawQuery("SELECT * FROM "+table+" group by ID", null);
Cursor.moveToPosition(row);
String s = Cursor.getString(1);
return s ;
} catch (Exception e) {
} finally {
if(Cursor!= null){
Cursor.close();
}
}
return null ;
}