我想構建一個本機模塊來對重啟設備進行本機反應。我發現這個在java中以編程方式關閉設備。它在 android studio 中單獨工作,但是當我嘗試在本機模塊中使用它時,出現以下錯誤https://pasteboard.co/IztJ6ll.jpgC:\Users\Ali\Desktop\Android\ReactNative\ReactNativeTest\android\app\src\main\java\com\reactnativetest\ToastModule.java:42: error: unreported exception IOException; must be caught or declared to be thrown Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" }); ^C:\Users\Ali\Desktop\Android\ReactNative\ReactNativeTest\android\app\src\main\java\com\reactnativetest\ToastModule.java:43: error: unreported exception InterruptedException; must be caught or declared to be thrown proc.waitFor(); ^2 errors> Task :app:compileDebugJavaWithJavac FAILEDFAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':app:compileDebugJavaWithJavac'.> Compilation failed; see the compiler error output for details.* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debugoption to get more log output. Run with --scan to get full insights.* Get more help at https://help.gradle.orgBUILD FAILED in 9s57 actionable tasks: 1 executed, 56 up-to-dateerror Could not install the app on the device, read the error above for details.Make sure you have an Android emulator running or a device connected and haveset up your Android development environment:https://facebook.github.io/react-native/docs/getting-started.htmlerror Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flagfor more details.
1 回答

慕斯709654
TA貢獻1840條經驗 獲得超5個贊
它就在日志中:
C:\Users\Ali\Desktop\Android\ReactNative\ReactNativeTest\android\app\src\main\java\com\reactnativetest\ToastModule.java:43: 錯誤:未報告異常 InterruptedException; 必須被捕獲或聲明拋出 proc.waitFor();
proc.waitFor()
拋出異常。您應該用 try-catch 包圍它,或者在方法簽名中聲明throws InterruptedException
并在其他地方處理它
添加回答
舉報
0/150
提交
取消