亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 NativeModules 時,在 React Native 中“必須被捕獲或聲明為拋出”

使用 NativeModules 時,在 React Native 中“必須被捕獲或聲明為拋出”

忽然笑 2023-09-06 17:00:05
我想構建一個本機模塊來對重啟設備進行本機反應。我發現這個在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并在其他地方處理它


查看完整回答
反對 回復 2023-09-06
  • 1 回答
  • 0 關注
  • 202 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號