When porting the Notifier example to my own project (basically copying the .h, .cpp and .java files over), and calling as shown in the Notifier example, I get this error:
W System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.app.Activity.getSystemService(java.lang.String)' on a null object reference
W System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.app.Activity.getSystemService(java.lang.String)' on a null object reference
To copy to clipboard, switch view to plain text mode
It occurs when running this Java code:
public static void notify(String s)
{
try {
if (m_notificationManager == null) {
m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
m_builder = new Notification.Builder(m_instance);
m_builder.setSmallIcon(R.drawable.icon);
m_builder.setContentTitle("A message from Qt!");
}
m_builder.setContentText(s);
m_notificationManager.notify(1, m_builder.build());
} catch(Throwable e) {
e.printStackTrace();
}
}
public static void notify(String s)
{
try {
if (m_notificationManager == null) {
m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
m_builder = new Notification.Builder(m_instance);
m_builder.setSmallIcon(R.drawable.icon);
m_builder.setContentTitle("A message from Qt!");
}
m_builder.setContentText(s);
m_notificationManager.notify(1, m_builder.build());
} catch(Throwable e) {
e.printStackTrace();
}
}
To copy to clipboard, switch view to plain text mode
To me it appears that the 'm_instance' variable is null... but why? If I open and run the Notifier example, it works fine.
Bookmarks