Android IR三星S4 irda服务失败

时间:2016-01-06 12:47:15

标签: android infrared

我尝试运行一个名为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)

此外,虽然应用程序构建成功但仍然显示1" irda"服务在以下代码行中:

irdaService = this.getSystemService("irda");

1 个答案:

答案 0 :(得分:1)

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

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之前的三星设备。