1

I tried running a GitHub library known as IrDude but it fails with the app force closing. It produces the following log:

   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)

Also though the app build successfully it still shows 1 error for the "irda" service in the following line of code :

irdaService = this.getSystemService("irda");
Ed Holloway-George
  • 5,092
  • 2
  • 37
  • 66
dexter87
  • 85
  • 1
  • 8
  • 4
    Possible duplicate of [IR Remote control app](http://stackoverflow.com/questions/24753587/ir-remote-control-app) – chedabob Jan 06 '16 at 12:49
  • 1
    As mentioned in the questioned linked by @chedabob, the "irda" service is only available on Samsung devices **prior** to KitKat. What OS version is your device running on? – Ed Holloway-George Jan 06 '16 at 12:51
  • @EdGeorge Mine uses version 5.0.1 – dexter87 Jan 06 '16 at 12:58
  • There's your problem! The "irda" service is no longer on your device, hence why you are getting the NPE – Ed Holloway-George Jan 06 '16 at 12:59
  • @EdGeorge:Thanks got the error removed by adding public void irInit4KitKat() { // Get a reference to the ConsumerIrManager mCIR = (ConsumerIrManager)getSystemService(Context.CONSUMER_IR_SERVICE); } – dexter87 Jan 06 '16 at 13:13
  • Consider creating an answer to your own question explaining the fix should one not be available on StackOverflow already – Ed Holloway-George Jan 06 '16 at 13:14

1 Answers1

1

Fixed my error by adding the following lines of code :

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);

}

The reason being that the "irda" service is only available on Samsung devices prior to KitKat.

dexter87
  • 85
  • 1
  • 8