I tried to send a custom data with acra(and without crashing my app) with these 2 lines
ACRA.getErrorReporter().putCustomData("myKey", "myValue");
ACRA.getErrorReporter().handleException(null);
But in the report that I received was just:
Report requested by developer
The problem is that in my report there was no "myKey" or "myValue". How can I fix that? Maybe the problem is that I didn't include some specific Report Fields?
After that I tried with just
ACRA.getErrorReporter().handleException(null);
and it worked as with 2 lines above??
ACRA is designed to capture unhandled exceptions. It also provides functionality to silently send handled exceptions. Sending null is way outside its design parameters.
Try sending an actual exception.
I did a little workaround to group specific messages sent by it's exception. I introduced "FakeException" and removed stack trace so the message would be smaller.
public class FakeException extends Exception {
#Override
public Throwable fillInStackTrace() {
return null;
}
#Override
public void setStackTrace(StackTraceElement[] trace) {
super.setStackTrace(null);
}
}
Now You can create another Exception that extends FakeException and do something like this:
public void SendUserReport(String reportText){
ACRA.getErrorReporter().putCustomData(USER_REPORT_CONTENT_TAG, reportText);
ACRA.getErrorReporter().handleSilentException(new NotificationFromUserFakeException());
ACRA.getErrorReporter().removeCustomData(USER_REPORT_CONTENT_TAG);
}
The following picture shows this report in Acralyzer (awesome software, definitely use it).
Related
I want to check exceptions and errors in my game in built up, but there is no debug console in game so I want to make one. Is there any way to get those errors from original console and write it on screen?
You can add a callback function to Application.logMessageReceived to receive the Debug.* messages. For example:
void Awake(){
Application.logMessageReceived += HandleLog;
}
private void HandleLog(string logString, string stackTrace, LogType type) {
// add them to some UI component for visualizing
}
I try to implement BugSense in my Android Application, but I'm not able to see the custom data I submitted. I really can't find out where the problem is, because I get an error report but without custom data. I implemented com.bugsense.trace.ExceptionCallback to receive all unhandled exceptions in the "lastBreath" method.
Here is my example code:
#Override
public void lastBreath(Exception arg0) {
Log.w(TAG, "executing lastBreath");
// adding current details to crash data
HashMap<String, String> errorDetails = new HashMap<String, String>();
errorDetails.put("testKey", "testValue");
errorDetails.put("testKey2", "testValue2");
BugSenseHandler.sendExceptionMap(errorDetails, arg0);
Log.w(TAG, "lastBreath executed");
}
This is generating an error report but I don't know where to find the custom values of "testKey" and "testKey2". I used the example code of the official site, so where is the problem? Thanks for your help.
I'm doing this data collection a little bit different from you. Here is how I do it:
//Call the initAndStartSession right before the setContentView of your activity (onCreate method)
BugSenseHandler.initAndStartSession(UserLogin.this, APIKEY);
//Add the values that you need to monitor
BugSenseHandler.addCrashExtraData("testKey", testKey);
BugSenseHandler.addCrashExtraData("testKey2", testKey2);
Once the error occurs, go to your BugSense errors page. (The link should look something like: https://www.bugsense.com/dashboard/project/YOUR_PROJECT_ID/errors/ ) and click on the exception link (as seen on the image bellow).
Now, once on the error page, click on the "Error Instances"
Now, if you click on the wrench Icon, you will see your "testKey" and "testKey2" available to be shown.
Hope it works!
In my Android application I utilize setDefaultUncaughtExceptionHandler to store information about unhandled exceptions locally on a user device. After some feedback I suspect that this code prevents the built-in Google's error-reporting feature from work, because I do not see error reports in the developer console, while exceptions are reported by users. Their devices are well past 2.2, where the error-reporting was introduced. Could it be that specific device with, say, 4.0.3 does not support this feature? If yes, how can I detect this programmatically?
I can't find information regarding this in Android documentation. I'd like both standard error-reporting and my custom handling work together. In my custom exception handler I call Thread.getDefaultUncaughtExceptionHandler() to get default handler, and in my implementation of uncaughtException I propagate exception to this default handler as well.
I first tried calling System.exit(1); as mentioned in this SO answer, but that didn't work.
Finally solved it by calling the uncaughtException(Thread thread, Throwable ex) again on Androids default UncaughtExceptionHandler (found it by checking the ACRA source code.
Example Activity
public class MainActivity extends Activity implements Thread.UncaughtExceptionHandler {
private Thread.UncaughtExceptionHandler _androidUncaughtExceptionHandler;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_androidUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
// Rest onCreate
setContentView(R.layout.main_activity);
}
//#Override
public void uncaughtException(Thread thread, Throwable ex) {
try {
// Do your stuff with the exception
} catch (Exception e) {
/* Ignore */
} finally {
// Let Android show the default error dialog
_androidUncaughtExceptionHandler.uncaughtException(thread, ex);
}
}
}
Yes, this will stop the inbuilt error report. The user is given a dialog when your app crashes, with an option to report the error via Google Play. However, if you use setDefaultUncaughtExceptionHandler() then the exception is handled within your app, and no option is given to report it.
I recommend that you integrate ACRA into your project, as it allows you to easily receive error reports upon crashes.
It seems that as of Android 2.2, there is a new feature for sending crash reports, as mentioned in the links:
http://www.androidcentral.com/new-android-app-crash-report-tool-already-and-running
http://android-developers.blogspot.com/2010/05/google-feedback-for-android.html
http://developer.android.com/sdk/android-2.2-highlights.html
http://www.youtube.com/watch?v=o8unC9bA4O8
How do I use this feature? Is it automatic for each application downloaded from the market (aka Google Play Store)?
Where can I find more info about this feature?
Also, is it possible to customize what is being sent, perhaps by using DefaultExceptionHandler, and put our own description of the crash?
NOTE: i know that there are plenty of tools for sending crash reports (like ACRA) , but i wish to check first if it's possible to use what's already given.
EDIT: I've succeeded modifying the exception that is passed further, hoping that this will also change the report that is sent to the developer website of Google.
Here's a sample code that is relevant for this:
private static class DefaultExceptionHandler implements java.lang.Thread.UncaughtExceptionHandler
...
#Override
public void uncaughtException(Thread t, Throwable e)
{
final StackTraceElement[] exceptionStackTrace = e.getStackTrace();
Exception exception = new Exception("my new exception!", e);
final StackTraceElement[] newExceptionStackTrace = new StackTraceElement[exceptionStackTrace.length + 1];
System.arraycopy(exceptionStackTrace, 0, newExceptionStackTrace, 1, exceptionStackTrace.length);
newExceptionStackTrace[0] = new StackTraceElement("TEST CLASS", "TEST METHOD", "TEST FILE", 0);
exception.setStackTrace(newExceptionStackTrace);
_defaultUEH.uncaughtException(t, exception); //this will hopefully call the default handling of the exception for reporting
}
What you have described sounds like the build in feature, and as far as I know, you cannot customize this. The data will be send to the googlePlay dev account which uploaded the app. I have seen customizations made by Sense, or Custom Roms. The only way to get your own Logs, is to use the DefaultErrorHandler you mentioned. As a good practice I would check, if you can catch the error yourself, (maybe log it somewhere). If not I would rethrow this error, to give the user a chance to give you hints , what he has done
I'm using addJavascriptInterface within my Android application to allow JavaScript to invoke functions I've created in my native Java application.
This worked well in Android 2.1, however in Android 2.2 I receive the error message "Error calling method on NPObject!"
When I instrument the method call the internals of the native method are getting called, however the exception is being throw in JavaScript.
I was getting this exact error:
Uncaught Error: Error calling method on NPObject!
Turns out I was attempting to invoke a JavascriptInterface function from a webview like so:
AndroidJS.populateField(field);
and on the Java side, the function didn't accept a parameter:
public void populateField() {}
Simply allowing the Java function to accept a parameter solved this error for me.
E.g.,
public void populateField(String field) {}
This may not be, and probably is not, the only reason this error could be thrown. This is simply how I resolved my specific scenario. Hope this helps! :)
OK, I have same problem as well, just in today.
What I did is putting code in UI Thread, like code below :
/**
* 給網頁Javascript呼叫的method
* Method for Javascript in HTML
* #param java.lang.String - Playlist ID
*/
public int callListByPID(final String pId)
{
Log.i(Constants.TAG, "PAD Playlist ID from HTML: "+pId);
runOnUiThread(new Runnable()
{
public void run()
{
// Put your code here...
}
});
return 1;
}
This solved my problem, and hope it can help some body... :-)
In my experience this problem is caused by Javascript interfaces bringing back objects that Javascript doesn't automatically identify.
In Android this is caused by wrappers like Boolean or Long in comparison to their native versions boolean and long.
//This will fail
public Long getmyLongVal() {
return 123456789;
}
//This will work
public long getMyNativeLongVal() {
return 123456789;
}
So remove your wrapper classes to any methods being used by Javascript if you want to avoid NPObject errors.
Here's a twist I found on this problem that could be useful for some of the folks running into this problem (and it likely explains intermittent failures that seem to defy explanation)...
If any exceptions are thrown (and not caught) in the return handler code prior to allowing the javascript interface callback to return clean, it will propagate back as a failed call and you will also get this error - and it would have nothing to do with missing functions or parameters.
The easiest way to find this case (whether or not you use this in your final implementation) is to push whatever handler code you have back onto the UI thread (the callback will not be on the UI thread) - this will allow the callback to return clean and any subsequent exceptions that occur will propagate properly up until you catch them or until the app crashes. Either way you will see exactly what is really happening. Otherwise the uncaught exception passes back to javascript where it will not be handled or reported in any way (unless you specifically built error trapping code into the JS you were executing).
Good Luck All.
bh
I had the same problem with Javascript-to-Java interface (WebView.addJavascriptInterface).
In Android 2.1 everything worked just fine but in Android 2.2 Javascript failed to call methods from this interface. It returned an error: Uncaught Error: Error calling method on NPObject!
It seems that on Android 2.2, the WebView has problem with Boolean data type returned from interface functions.
Changing:
public Boolean test_func() { return true; }
... to:
public int test_func() { return 1; }
... solved the problem.
This I believe is no longer supported anymore ( Always game NPObject error ) .
Please refer to the answer in this thread
Visit open an activity from a CordovaPlugin