java.lang.NullPointerException

Appcelerator JIRA | Benjamin Hatfield | 2 years ago
  1. 0

    REPRODUCTION: Build the application using a master version of the Titanium SDK and run in the Genymotion emulator. Click the 'Add Notification' button. Back out of the application till it closes. Wait 30s for the notification to trigger. RESULTS: When the service tries to call the Android.NotificationManager.notify() method it throws an exception. {noformat} [WARN] : W/System.err java.lang.NullPointerException [WARN] : W/System.err at android.app.Notification$Builder.applyStandardTemplate(Notification.java:1630) [WARN] : W/System.err at android.app.Notification$Builder.makeContentView(Notification.java:1752) [WARN] : W/System.err at android.app.Notification$Builder.buildUnstyled(Notification.java:1800) [WARN] : W/System.err at android.app.Notification$Builder.build(Notification.java:1872) [WARN] : W/System.err at android.support.v4.app.NotificationCompatKitKat$Builder.build(NotificationCompatKitKat.java:114) [WARN] : W/System.err at android.support.v4.app.NotificationCompat$NotificationCompatImplKitKat.build(NotificationCompat.java:633) [WARN] : W/System.err at android.support.v4.app.NotificationCompat$Builder.build(NotificationCompat.java:1503) [WARN] : W/System.err at ti.modules.titanium.android.notificationmanager.NotificationProxy.buildNotification(NotificationProxy.java:315) [WARN] : W/System.err at ti.modules.titanium.android.notificationmanager.NotificationManagerModule.notify(NotificationManagerModule.java:78) [WARN] : W/System.err at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method) [WARN] : W/System.err at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:177) [WARN] : W/System.err at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:299) [WARN] : W/System.err at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:203) [WARN] : W/System.err at android.os.Handler.dispatchMessage(Handler.java:98) [WARN] : W/System.err at android.os.Looper.loop(Looper.java:136) [WARN] : W/System.err at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112) [WARN] : TiExceptionHandler (main) [5002,552687] Activity is null or already finishing, skipping dialog. [ERROR] : V8Exception Exception occurred at ExampleService.js:47 Uncaught Error Java Exception occurred {noformat} OTHER INFO: If you hit the home button instead to close the application, the notification works. If you remove the notify call from the service, the service runs OK. This works fine with 3.4.0.GA and 3.4.1.GA. *./Resources/app.js* {code} var win = Ti.UI.createWindow(); var btn = Ti.UI.createButton({ title : 'Add Notification' }); btn.addEventListener('click', function(e) { var intent = Ti.Android.createServiceIntent({ url : 'ExampleService.js' }); intent.putExtra('title' , 'Richard III'); intent.putExtra('message' , 'Now is the winter of our discontent...'); intent.putExtra('timestamp', new Date(new Date().getTime() + 30 * 1000)); intent.putExtra('interval', 5000); Ti.Android.startService(intent); Ti.App.Properties.setBool('bind', false); }); win.add(btn); win.open(); {code} *./Resources/ExampleService.js* {code} var service = Ti.Android.currentService; var serviceIntent = service.getIntent(); var timestamp = new Date(serviceIntent.getStringExtra('timestamp')); Ti.API.info(service.serviceInstanceId); if (!Ti.App.Properties.getBool('bind')) { service.addEventListener("taskremoved", function(){ Ti.API.info("**************************** taskremoved fired"); }); service.addEventListener("pause", function(){ Ti.API.info("**************************** pause fired"); }); service.addEventListener("resume", function(){ Ti.API.info("**************************** resume fired"); }); Ti.App.Properties.setBool('bind', true); } if (new Date() > timestamp) { // Grab extra data sent with the intent var title = serviceIntent.getStringExtra('title'); var message = serviceIntent.getStringExtra('message'); // Create an intent that launches the application var intent = Ti.Android.createIntent({ action : Ti.Android.ACTION_MAIN, className: 'com.appcelerator.testapns.ActionnewsActivity', packageName: 'com.appcelerator.testapns', flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP }); intent.addCategory(Ti.Android.CATEGORY_LAUNCHER); // Create notification var notification = Ti.Android.createNotification({ contentIntent : Ti.Android.createPendingIntent({intent : intent}), contentTitle : title, contentText : message }); // Send the notification Ti.Android.NotificationManager.notify(service.serviceInstanceId, notification); // Stop the service once the notification is sent Ti.Android.stopService(serviceIntent); } {code} *Replace android element with the following in tiapp.xml* {code} <android xmlns:android="http://schemas.android.com/apk/res/android"> <services> <service url="ExampleService.js" type="interval"/> </services> </android> {code}

    Appcelerator JIRA | 2 years ago | Benjamin Hatfield
    java.lang.NullPointerException
  2. 0

    REPRODUCTION: Build the application using a master version of the Titanium SDK and run in the Genymotion emulator. Click the 'Add Notification' button. Back out of the application till it closes. Wait 30s for the notification to trigger. RESULTS: When the service tries to call the Android.NotificationManager.notify() method it throws an exception. {noformat} [WARN] : W/System.err java.lang.NullPointerException [WARN] : W/System.err at android.app.Notification$Builder.applyStandardTemplate(Notification.java:1630) [WARN] : W/System.err at android.app.Notification$Builder.makeContentView(Notification.java:1752) [WARN] : W/System.err at android.app.Notification$Builder.buildUnstyled(Notification.java:1800) [WARN] : W/System.err at android.app.Notification$Builder.build(Notification.java:1872) [WARN] : W/System.err at android.support.v4.app.NotificationCompatKitKat$Builder.build(NotificationCompatKitKat.java:114) [WARN] : W/System.err at android.support.v4.app.NotificationCompat$NotificationCompatImplKitKat.build(NotificationCompat.java:633) [WARN] : W/System.err at android.support.v4.app.NotificationCompat$Builder.build(NotificationCompat.java:1503) [WARN] : W/System.err at ti.modules.titanium.android.notificationmanager.NotificationProxy.buildNotification(NotificationProxy.java:315) [WARN] : W/System.err at ti.modules.titanium.android.notificationmanager.NotificationManagerModule.notify(NotificationManagerModule.java:78) [WARN] : W/System.err at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method) [WARN] : W/System.err at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:177) [WARN] : W/System.err at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:299) [WARN] : W/System.err at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:203) [WARN] : W/System.err at android.os.Handler.dispatchMessage(Handler.java:98) [WARN] : W/System.err at android.os.Looper.loop(Looper.java:136) [WARN] : W/System.err at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112) [WARN] : TiExceptionHandler (main) [5002,552687] Activity is null or already finishing, skipping dialog. [ERROR] : V8Exception Exception occurred at ExampleService.js:47 Uncaught Error Java Exception occurred {noformat} OTHER INFO: If you hit the home button instead to close the application, the notification works. If you remove the notify call from the service, the service runs OK. This works fine with 3.4.0.GA and 3.4.1.GA. *./Resources/app.js* {code} var win = Ti.UI.createWindow(); var btn = Ti.UI.createButton({ title : 'Add Notification' }); btn.addEventListener('click', function(e) { var intent = Ti.Android.createServiceIntent({ url : 'ExampleService.js' }); intent.putExtra('title' , 'Richard III'); intent.putExtra('message' , 'Now is the winter of our discontent...'); intent.putExtra('timestamp', new Date(new Date().getTime() + 30 * 1000)); intent.putExtra('interval', 5000); Ti.Android.startService(intent); Ti.App.Properties.setBool('bind', false); }); win.add(btn); win.open(); {code} *./Resources/ExampleService.js* {code} var service = Ti.Android.currentService; var serviceIntent = service.getIntent(); var timestamp = new Date(serviceIntent.getStringExtra('timestamp')); Ti.API.info(service.serviceInstanceId); if (!Ti.App.Properties.getBool('bind')) { service.addEventListener("taskremoved", function(){ Ti.API.info("**************************** taskremoved fired"); }); service.addEventListener("pause", function(){ Ti.API.info("**************************** pause fired"); }); service.addEventListener("resume", function(){ Ti.API.info("**************************** resume fired"); }); Ti.App.Properties.setBool('bind', true); } if (new Date() > timestamp) { // Grab extra data sent with the intent var title = serviceIntent.getStringExtra('title'); var message = serviceIntent.getStringExtra('message'); // Create an intent that launches the application var intent = Ti.Android.createIntent({ action : Ti.Android.ACTION_MAIN, className: 'com.appcelerator.testapns.ActionnewsActivity', packageName: 'com.appcelerator.testapns', flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP }); intent.addCategory(Ti.Android.CATEGORY_LAUNCHER); // Create notification var notification = Ti.Android.createNotification({ contentIntent : Ti.Android.createPendingIntent({intent : intent}), contentTitle : title, contentText : message }); // Send the notification Ti.Android.NotificationManager.notify(service.serviceInstanceId, notification); // Stop the service once the notification is sent Ti.Android.stopService(serviceIntent); } {code} *Replace android element with the following in tiapp.xml* {code} <android xmlns:android="http://schemas.android.com/apk/res/android"> <services> <service url="ExampleService.js" type="interval"/> </services> </android> {code}

    Appcelerator JIRA | 2 years ago | Benjamin Hatfield
    java.lang.NullPointerException
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at android.app.Notification$Builder.applyStandardTemplate()
    2. Android Platform
      Notification$Builder.build
      1. android.app.Notification$Builder.applyStandardTemplate(Notification.java:1630)
      2. android.app.Notification$Builder.makeContentView(Notification.java:1752)
      3. android.app.Notification$Builder.buildUnstyled(Notification.java:1800)
      4. android.app.Notification$Builder.build(Notification.java:1872)
      4 frames
    3. Android Support v4
      NotificationCompat$Builder.build
      1. android.support.v4.app.NotificationCompatKitKat$Builder.build(NotificationCompatKitKat.java:114)
      2. android.support.v4.app.NotificationCompat$NotificationCompatImplKitKat.build(NotificationCompat.java:633)
      3. android.support.v4.app.NotificationCompat$Builder.build(NotificationCompat.java:1503)
      3 frames
    4. ti.modules.titanium
      NotificationManagerModule.notify
      1. ti.modules.titanium.android.notificationmanager.NotificationProxy.buildNotification(NotificationProxy.java:315)
      2. ti.modules.titanium.android.notificationmanager.NotificationManagerModule.notify(NotificationManagerModule.java:78)
      2 frames
    5. org.appcelerator.kroll
      V8Runtime.handleMessage
      1. org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
      2. org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:177)
      3. org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:299)
      4. org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:203)
      4 frames
    6. Android Platform
      Looper.loop
      1. android.os.Handler.dispatchMessage(Handler.java:98)
      2. android.os.Looper.loop(Looper.java:136)
      2 frames
    7. org.appcelerator.kroll
      KrollRuntime$KrollRuntimeThread.run
      1. org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
      1 frame