2016-01-06 78 views
1

我試着運行一個名爲IrDude的GitHub庫,但它失敗,應用程序強制關閉。它生成以下日誌:Android IR三星S4 irda服務失敗

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個錯誤:

irdaService = this.getSystemService("irda"); 
+4

[IR Remote control app]的可能重複(http://stackoverflow.com/questions/24753587/ir-remote-control-app) – chedabob

+1

正如在@chedabob鏈接的提問中提到的那樣,「irda」服務是僅適用於Samsung設備**之前**至KitKat。你的設備上運行什麼操作系統版本? –

+0

@EdGeorge Mine使用版本5.0.1 – dexter87

回答

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之前的三星設備。