Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 应用程序在启动时读取资产中的文件时崩溃_Java_Android_Json_File - Fatal编程技术网

Java 应用程序在启动时读取资产中的文件时崩溃

Java 应用程序在启动时读取资产中的文件时崩溃,java,android,json,file,Java,Android,Json,File,我正在尝试从我的资产文件夹中的文件接收JSON字符串,但是在应用程序打开后不久,它就会崩溃,出现以下日志 $ 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 'huaw

我正在尝试从我的资产文件夹中的文件接收JSON字符串,但是在应用程序打开后不久,它就会崩溃,出现以下日志

$ 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;
    }

“它与下面的logcat一起崩溃”--没有崩溃的证据。“错误似乎显示在这些行上”——这不是堆栈跟踪,这将是崩溃的证据。那么应用程序崩溃了,这就是showsHow的全部内容。你确定应用程序崩溃了吗?如果您在Logcat中关闭按进程过滤,您是否看到可能的堆栈跟踪?如果readFileLines是一个函数,我看不到任何东西,那么为什么要调用它?