【发布时间】:2019-03-26 05:39:36
【问题描述】:
在我的应用程序中,我使用服务从 JSON 获取数据,然后将其保存在数据库中。
当我在新设备上运行应用程序时,它会崩溃没有任何错误!
但是当我注释掉用于加载到 TextViews 的代码时,它运行良好。之后,即使我将代码带回给 TextViews,它也能正常工作。
更新: 在我注释掉用于提供 TextViews 的代码之前,用于提供数据库的服务不会运行。
提供 TextViews 的代码:
//this service contains JSON to DB code
Intent intent = new Intent(MainActivity.this, GetdataService.class);
startService(intent);
cursor = DBOps.Ops.getTheOne();
cursor.moveToNext();
//app crashes at this line
wordText.setText(cursor.getString(cursor.getColumnIndex(DBContracts.Word.TITLE)));
phonetic = cursor.getString(cursor.getColumnIndex(DBContracts.Word.PHONETIC));
meaningText.setText(cursor.getString(cursor.getColumnIndex(DBContracts.Word.MEANING)));
exampleText.setText(cursor.getString(cursor.getColumnIndex(DBContracts.Word.EXAMPLE)));
获取物品的方法:
public static Cursor getTheOne(){
return db.query(DBContracts.Word.TABLE_NAME,
null,
null,
null,
null,
null,
DBContracts.Word._ID + " DESC LIMIT 1"
);
}
【问题讨论】:
-
请提供崩溃日志 - 并且需要在日志中的某处提到错误
-
@WarrenFaith 这就是重点。没有错误!! Android Monitor 没有任何反应!
-
logcat 中没有没有痕迹的崩溃...我认为您的 .光标为空
-
@Bruno 没有输入光标,我已经检查过了。
-
您确定您的数据库包含
DBContracts.Word.TITLE列吗?很抱歉,如果没有日志跟踪,将很难为您提供帮助
标签: java android json database sqlite