我尝试运行名为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 - Android IR Samsung S4 irda服务失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34633539/

10-12 02:18