java - 读取资产中的文件时应用程序在启动时崩溃
问题描述
我正在尝试从我的资产文件夹中的文件中接收 JSON 字符串,但是在应用程序打开后不久,它会因以下 logcat 而崩溃
$ adb shell am start -n "com.ashb.osrstimers/com.ashb.osrstimers.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 10303 on device 'huawei-mar_lx1a-JRQDU20512003719'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/ActivityThread: Attach thread to application
I/ashb.osrstimer: QarthPatchMonintor::Init
QarthPatchMonintor::StartWatch
QarthPatchMonintor::WatchPackage: /data/hotpatch/fwkhotpatch/
QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/com.ashb.osrstimers
QarthPatchMonintor::CheckAndWatchPatch: /data/hotpatch/fwkhotpatch/all
QarthPatchMonintor::Run
I/ashb.osrstimer: QarthPatchMonintor::Reading
I/ashb.osrstimer: QarthPatchMonintor::CheckNotifyEvent
QarthPatchMonintor::CheckNotifyEvent before read
I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.ashb.osrstimers#10247#256
I/HwApiCacheMangerEx: apicache path=/storage/emulated/0 state=mounted key=com.ashb.osrstimers#10247#0
I/AwareBitmapCacher: init processName:com.ashb.osrstimers pid=10303 uid=10247
E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@5e2870f
E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@b34439c
D/AwareBitmapCacher: handleInit switch not opened pid=10303
该错误似乎显示在这些行上:
E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@5e2870f
E/AwareLog: AtomicFileUtils: readFileLines file not exist: android.util.AtomicFile@b34439c
这是我从 json 文件中读取数据的代码:
private String getJSONData() {
String json_string;
AssetManager assetManager = getAssets();
InputStream input;
try {
input = assetManager.open("timers.json");
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
json_string = new String(buffer);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return json_string;
}
解决方案
推荐阅读
- git - 在遍历所有子模块列表时避免子模块
- python-3.x - time.time_ns() 在 macOS 上没有正确返回纳秒?
- arrays - Kotlin - 在数组中查找匹配的对象
- scripting - “|”之间有区别吗 和“¦”在脚本方面?
- oracle - 我在存储过程(包)中面临删除操作的问题
- spring - 如何使用 Spring Rabbitmq 连接到多个 Rabbitmq 节点?
- r - 有没有办法为pdf制作没有线条/边框的kable?
- javascript - 在模态内部单击几次后,模态弹出窗口移动到左侧
- python - 函数可以改变变量的内容吗?
- php - 通过比较两个数据库表 Codeigniter/Mysql 删除匹配值