gpt4 book ai didi

Android IR Samsung S4 irda 服务失败

转载 作者:行者123 更新时间:2023-11-30 01:39:51 26 4
gpt4 key购买 nike

我尝试运行一个名为 IrDude 的 GitHub 库但它因应用程序强制关闭而失败。它产生以下日志:

   FATAL EXCEPTION: main
Process: com.rngtng.irdude, PID: 28350
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rngtng.irdude/com.rngtng.irdude.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2702)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
at com.rngtng.irdude.MainActivity.irInit(MainActivity.java:57)
at com.rngtng.irdude.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

此外,尽管应用程序构建成功,但在以下代码行中仍然显示“irda”服务的 1 个错误:

irdaService = this.getSystemService("irda");

最佳答案

通过添加以下代码行修复了我的错误:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){

irInit4KitKat();
}else{
irInit4JellyBean();
}

@TargetApi(Build.VERSION_CODES.KITKAT)
public void irInit4KitKat() {

// Get a reference to the ConsumerIrManager
mCIR = (ConsumerIrManager)getSystemService(Context.CONSUMER_IR_SERVICE);

}

原因是“irda”服务仅适用于 KitKat 之前的三星设备。

关于Android IR Samsung S4 irda 服务失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34633539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com