From efb42cedafafb5746b267c630b5e5650cb72b0f5 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 31 Oct 2023 09:26:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=AF=E5=81=9C=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xypower/mpapp/MainActivity.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/MainActivity.java b/app/src/main/java/com/xypower/mpapp/MainActivity.java index dafd10e8..a9f14973 100644 --- a/app/src/main/java/com/xypower/mpapp/MainActivity.java +++ b/app/src/main/java/com/xypower/mpapp/MainActivity.java @@ -267,7 +267,7 @@ public class MainActivity extends AppCompatActivity { AppConfig curAppConfig = retrieveAndSaveAppConfig(); - if (TextUtils.isEmpty(appConfig.cmdid) || TextUtils.isEmpty(appConfig.server) || appConfig.port == 0) { + if (TextUtils.isEmpty(curAppConfig.cmdid) || TextUtils.isEmpty(curAppConfig.server) || curAppConfig.port == 0) { return; } Intent intent = new Intent(MainActivity.this, MicroPhotoService.class); @@ -576,15 +576,19 @@ public class MainActivity extends AppCompatActivity { dataPath.mkdirs(); } - inputStreamReader = new InputStreamReader(new FileInputStream(new File(appPath + "App.json")), "UTF-8"); - bufferedReader = new BufferedReader(inputStreamReader); - String line; StringBuilder stringBuilder = new StringBuilder(); - while ((line = bufferedReader.readLine()) != null) { - stringBuilder.append(line); + File file = new File(dataPath, "App.json"); + if (file.exists()) { + inputStreamReader = new InputStreamReader(new FileInputStream(file), "UTF-8"); + bufferedReader = new BufferedReader(inputStreamReader); + String line; + + while ((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } } - JSONObject jsonObject = new JSONObject(stringBuilder.toString()); + JSONObject jsonObject =stringBuilder.length() > 0 ? (new JSONObject(stringBuilder.toString())) : (new JSONObject()); jsonObject.put("CMDID", cmdid); jsonObject.put("Server", server);