SuperMonster003 / AutoJs6

安卓平台 JavaScript 自动化工具 (Auto.js 二次开发项目)
https://docs.autojs6.com
Mozilla Public License 2.0
2.64k stars 768 forks source link

工程型代码删除 project.json 后执行报错空指针异常。 #268

Open kvii opened 1 month ago

kvii commented 1 month ago

如题。期望给一个更友好的提示。

复现步骤:

  1. app 主页点击右下 fab,点击“项目”新建项目。名称随意。(用 vscode 同步工程也是一样的)
  2. 点进创建的项目中。删除 project.json。
  3. 点击项目上的运行按钮。

期望结果: Toast 提示 project.json 不存在。

实际结果: Toast 提示 NullPointerException。

截图:

日志:

2024-10-30 17:58:02.314  4150-4150  Shell                   org.autojs.autojs6                   D  onOutput: 0000 0000 00000000
2024-10-30 17:58:02.319  4150-4150  Shell                   org.autojs.autojs6                   D  onOutput: 0000 0000 00000000
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W  java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.autojs.autojs.project.ProjectConfig.getMainScriptFile()' on a null object reference
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at org.autojs.autojs.project.ProjectLauncher.<init>(ProjectLauncher.java:18)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at org.autojs.autojs.ui.explorer.ExplorerProjectToolbar.run(ExplorerProjectToolbar.java:89)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at org.autojs.autojs.ui.explorer.ExplorerProjectToolbar.lambda$init$0(ExplorerProjectToolbar.java:63)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at org.autojs.autojs.ui.explorer.ExplorerProjectToolbar.$r8$lambda$7XYDI9y4RunEb2UoL_4xJnVp8pk(Unknown Source:0)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at org.autojs.autojs.ui.explorer.ExplorerProjectToolbar$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at android.view.View.performClick(View.java:7659)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at android.view.View.performClickInternal(View.java:7636)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at android.view.View$PerformClick.run(View.java:30156)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at android.os.Handler.handleCallback(Handler.java:958)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at android.os.Handler.dispatchMessage(Handler.java:99)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at android.os.Looper.loopOnce(Looper.java:205)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at android.os.Looper.loop(Looper.java:294)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at android.app.ActivityThread.main(ActivityThread.java:8177)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at java.lang.reflect.Method.invoke(Native Method)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
2024-10-30 17:58:02.410  4150-4150  System.err              org.autojs.autojs6                   W      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
2024-10-30 17:58:02.440  4150-4150  NotificationObserver    org.autojs.autojs6                   D  onNotification: [Attempt to invoke virtual method 'java.lang.String org.autojs.autojs.project.ProjectConfig.getMainScriptFile()' on a null object reference, AutoJs6]; EventType: TYPE_NOTIFICATION_STATE_CHANGED; EventTime: 3315809; PackageName: org.autojs.autojs6; MovementGranularity: 0; Action: 0; ContentChangeTypes: []; WindowChangeTypes: [] [ ClassName: android.widget.Toast; Text: [Attempt to invoke virtual method 'java.lang.String org.autojs.autojs.project.ProjectConfig.getMainScriptFile()' on a null object reference, AutoJs6]; ContentDescription: null; ItemCount: -1; CurrentItemIndex: -1; Enabled: false; Password: false; Checked: false; FullScreen: false; Scrollable: false; ImportantForAccessibility: true; AccessibilityDataSensitive: false; BeforeText: null; FromIndex: -1; ToIndex: -1; ScrollX: 0; ScrollY: 0; MaxScrollX: 0; MaxScrollY: 0; ScrollDeltaX: -1; ScrollDeltaY: -1; AddedCount: -1; RemovedCount: -1; ParcelableData: null; DisplayId: -1 ]; recordCount: 0
SuperMonster003 commented 3 weeks ago

感谢反馈, 后续版本会尽可能多地处理与 project.json 相关的各种异常, 除 issue 提及的 project.json 文件不存在外, 还会包含 project 文件内容为空, 内容缺少关键信息, 出错时提示用户使用 UI 页面建立新文件等. 上述包含的异常均会给出明确提示, 并在控制台消息中有所体现.

Sent from my XQ-DQ72 using FastHub