I was trying to use the onBackPressed()
method to open an activity that I need and close the existing one but the application close unexpectedly; I put a try catch if I can see the error but the variable "e
" comes null
, the only thing that show me something is the log, also I try to search for a solution that shows the log but it seems that those solutions do not apply to my case.
Here is my code:
@Override
public void onBackPressed() {
try {
Intent intent = new Intent(ScheduleAppointment.this, CreateAppointment.class);
ScheduleAppointment.this.startActivity(intent);
ScheduleAppointment.this.finish();
}catch (Exception e){
e.printStackTrace();
}
}
and here is the log:
02-26 12:21:44.062 2385-2385/com.saludtotal.beqs.saludtotalafiliados E/InputEventSender﹕ Exception dispatching finished signal.
02-26 12:21:44.063 2385-2385/com.saludtotal.beqs.saludtotalafiliados E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
02-26 12:21:44.114 2385-2385/com.saludtotal.beqs.saludtotalafiliados E/MessageQueue-JNI﹕ java.lang.NullPointerException
at com.saludtotal.beqs.saludtotalafiliados.ScheduleAppointment.onBackPressed(ScheduleAppointment.java:222)
at android.app.Activity.onKeyUp(Activity.java:2201)
at android.view.KeyEvent.dispatch(KeyEvent.java:2676)
at android.app.Activity.dispatchKeyEvent(Activity.java:2431)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1962)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3921)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3895)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3471)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3578)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3479)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3635)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3471)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3479)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3471)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3611)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3777)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2012)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1706)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1697)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1989)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:5097)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
02-26 12:21:44.114 2385-2385/com.saludtotal.beqs.saludtotalafiliados D/AndroidRuntime﹕ Shutting down VM
02-26 12:21:44.115 2385-2385/com.saludtotal.beqs.saludtotalafiliados W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41d93d40)
02-26 12:21:44.139 2385-2385/com.saludtotal.beqs.saludtotalafiliados E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.saludtotal.beqs.saludtotalafiliados, PID: 2385
java.lang.NullPointerException
at com.saludtotal.beqs.saludtotalafiliados.ScheduleAppointment.onBackPressed(ScheduleAppointment.java:222)
at android.app.Activity.onKeyUp(Activity.java:2201)
at android.view.KeyEvent.dispatch(KeyEvent.java:2676)
at android.app.Activity.dispatchKeyEvent(Activity.java:2431)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1962)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3921)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3895)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3471)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3578)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3479)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3635)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3471)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3479)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3452)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3471)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3611)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3777)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2012)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1706)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1697)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1989)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:5097)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
A curious thing is if for example I change the class That I want to reopen I t works without any problem, but I need when the user press the back button to open that specific class. Any help will be appreciated.
Edit:
I am using a Motorola g 2nd generation with android version 4.4.4 and a Samsung galaxy tab 7.7 p6800 with android version 4.0.4 both show me the same error.
On thing happen when I remove the try catch clauses and I am debugging step by step, on the following line of code
ScheduleAppointment.this.startActivity(intent);
redirect to the ZygoteInit.java class and in this method is were it shows the error on the log:
/**
* Runs the zygote process's select loop. Accepts new connections as
* they happen, and reads commands from connections one spawn-request's
* worth at a time.
*
* @throws MethodAndArgsCaller in a child process when a main() should
* be executed.
*/
private static void runSelectLoop(String abiList) throws MethodAndArgsCaller {
ArrayList<FileDescriptor> fds = new ArrayList<FileDescriptor>();
ArrayList<ZygoteConnection> peers = new ArrayList<ZygoteConnection>();
FileDescriptor[] fdArray = new FileDescriptor[4];
fds.add(sServerSocket.getFileDescriptor());
peers.add(null);
int loopCount = GC_LOOP_COUNT;
while (true) {
int index;
/*
* Call gc() before we block in select().
* It's work that has to be done anyway, and it's better
* to avoid making every child do it. It will also
* madvise() any free memory as a side-effect.
*
* Don't call it every time, because walking the entire
* heap is a lot of overhead to free a few hundred bytes.
*/
if (loopCount <= 0) {
gc();
loopCount = GC_LOOP_COUNT;
} else {
loopCount--;
}
try {
fdArray = fds.toArray(fdArray);
index = selectReadable(fdArray);
} catch (IOException ex) {
throw new RuntimeException("Error in select()", ex);
}
if (index < 0) {
throw new RuntimeException("Error in select()");
} else if (index == 0) {
ZygoteConnection newPeer = acceptCommandPeer(abiList);
peers.add(newPeer);
fds.add(newPeer.getFileDescriptor());
} else {
boolean done;
done = peers.get(index).runOnce();
if (done) {
peers.remove(index);
fds.remove(index);
}
}
}
}
and more precisely in this part:
if (done) {
peers.remove(index);
fds.remove(index);
}