The method 'then' was called on null. Receiver: null - android

I am new to mobile application development. I am getting such an error. I think there is something wrong with the code block above.
This is a notebook project. When I click the button, I get this error when the new annotation screen should open.

Related

How does Android Studio know to display the "Toast created but not shown: did you forget to call show()?" warning?

When you create a Toast but do not call the show() method Android Studio shows an tooltip saying: "Toast created but not shown: did you forget to call show()?" another example is not calling commit or apply when putting values into a SharedPreferencesEditor object and a tooltip being displayed.
Is this just Android Studio being helpful or is there a way to define that after a method is called another method should be called?
This is just Intellij (Android Studio) being smart enough to figure through static code analysis.
There is no way to tell the compiler that after such method another method should run. The closest thing to it is writing unit tests and even that only notifies you during your test runs.

How to debug android callbacks?

I am trying to use the Eclipse debugger to debug my Android application, but it doesn't seem to be working. I have a callback in my MasterActivity.java file for onOptionsItemSelected, and I set a breakpoint in this method at a point that I know is being hit. I then right click my application, and go to Debug As -> Android Application. When I click the button in the ActionBar that triggers this callback and should start the debugging process, my program just continues like my breakpoint is not there. I must be missing something basic here, but I'm not sure what.
Simon's suggestion to add a Log message is a good start to ensure that the callback is being called, unless there is already some other evidence unique to the callback that it is being triggered. We can only guess as you haven't included any code, and nothing wastes time like a programmer assuming they are correct, myself included ;-)
However, try adding a call to waitForDebugger() just prior to the line with the breakpoint active.
A good way to check if an item, in this case a menu item I guess, is to use the method Log.d(String tag, String message). So in your onOptionsItemSelected event handler, you can add e.g Log.d("Debug", "Options item is selected"). It isn't necessary to use Debug As, Run As will work too. The log message will be displayed in blue in the LogCat in Eclipse.

Handling exceptions in android intents

I'm a totally Android newbie who's learing about intents. I'm working on a small application to stream youtube videos. My question is do I have to do anything especial when invoking an intent? what happens when the intent fails? I'm I responsible for handling exceptions? Do I have to do register the intent so I can invoke it? Thanks
when you are invoking an intent, it means you will deal with any of the provided components like Activity, Receiver, service ect . so the case where operation inside this component throws some exception, for example an activity throws a NPE , that should be handlelled withing that component itself or within activity for this example . even if you will handle it at the time of invocation , despite being unusual and not recommended approach , like this :
try
{
startActivity( . .);
}
catch
{
}
this will not going to handle exception, thrown from inside activity code .
so conclusion is that neither android OS nor you should handle it at the time of invocation, but handle them at specific places where possible that any exception can accrue .

Android HP ePrint activity response code

I'm working on an android app that can call upon HP ePrint app to perform printing wirelessly. The printing function have been tested working. However, after the user press the print button, i would like my app to come to the front instead of it staying at the ePrint app, and for that I'll need the response code from the ePrint app.
I googled that one way to do it is by calling the intent with startActivityForResult, as:
startActivityForResult(intent, REQUEST_CODE_PRINT_FILE);
however i failed to find the value for the variable REQUEST_CODE_PRINT_FILE. Do i need to know the value of the variable or i can simply use RESULT_OK in my case?
Thanx.
REQUEST_CODE_PRINT_FILE can be a any int value >= 0 , this value will be returned back to you onActivityResult() arguments once the printer Activity destroyed.
please check the docs.
http://developer.android.com/reference/android/app/Activity.html#startActivityForResult%28android.content.Intent,%20int%29

How to guarantee an exception display on android under ANY circumstances?

I read a lot about using Toast or Log and putting them into Thread.setDefaultUncaughtExceptionHandler(...).
But I just can't get ALL exceptions displayed.
Please tell me (or point me to a resource) where it is described how to to it.
With working examples, when possible.
Thank you.
My guess is: when certain things go wrong (some global exception which destroys the whole app), toasts can't be displayed anymore.
If you are just developing don't try to use Toasts to display exceptions just work with Log.e() and the other Log functions it will all get displayed in LogCat you won't loose any exceptions. If you want to notify the UI that an Exception happened do it with a BroadcastReciever. So you have the place where you catch the Exception that fires an Intent which contains the message as an extra and in your Activity you just have to
registerReceiver(receiver, new IntentFilter("SOME_STRING_IDENTIFYING_THE_INTENT"));
Make sure you unregister the Receiver in the Activities onPause method.
The BroadcastReciever has a onReceive method that you can use to fire of the Toast.

Categories

Resources