Sunday 3 April 2016

java - Getting the "logcat like" from the stack trace Output

I'm trying to get the complete exception log "like we have in the android studio"
from the error object that we have in the App class
to be more specific this is my App.java



import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;


/**
* Created by informatic on 17/03/2018.
*/

public class App extends Application {

@Override
public void onCreate() {
super.onCreate();


Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
e.printStackTrace();
StringBuilder massage=new StringBuilder();
for (int i = 0; i < e.getStackTrace().length; i++) {
massage.append(e.getStackTrace()[i].toString());
}
String s=massage.toString();
System.out.print(s);
});
}


@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}


after a NullPointerException this is what the String s will contains after the Exception





android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2469)android.app.ActivityThread.access$1100(ActivityThread.java:151)android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)android.os.Handler.dispatchMessage(Handler.java:110)android.os.Looper.loop(Looper.java:193)android.app.ActivityThread.main(ActivityThread.java:5551)java.lang.reflect.Method.invokeNative(Native Method)java.lang.reflect.Method.invoke(Method.java:515)com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)com.android.internal.os.ZygoteInit.main(ZygoteInit.java:730)dalvik.system.NativeStart.main(Native Method)




but on the other hand the logcat will print this




com.automata4.www.sanad E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.automata4.www.sanad, PID: 31429

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.automata4.www.sanad/com.automata4.www.sanad.frontend.activities.home.HomeActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2469)
at android.app.ActivityThread.access$1100(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5551)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:730)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.automata4.www.sanad.frontend.activities.home.HomeActivity.getAndSetUi(HomeActivity.java:48)
at com.automata4.www.sanad.frontend.activities.home.HomeActivity.onCreate(HomeActivity.java:42)
at android.app.Activity.performCreate(Activity.java:5310)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2381)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2469) 

at android.app.ActivityThread.access$1100(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5551) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:730) 
at dalvik.system.NativeStart.main(Native Method) 





so my question is
Is there any way to get like the previous output from the e object so that I could send this complete exception to my server?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...