Discussion Forums  >  Crashes, Memory Warnings

Replies: 12    Views: 735

g1pro757
Android Fan
Profile
Posts: 12
Reg: Feb 12, 2015
new york
120
02/28/15 02:50 PM (3 years ago)

Crash when back button pressed

I have created a radio stream app which now is working really well. The problem is when I am in the radio stream screen when i press the back button the app crashes. Anybody have an idea why?

this is what i get in the console

02-28 16:41:44.471 24931-24931/com.radioalmacristiana E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.radioalmacristiana, PID: 24931
java.lang.NullPointerException
at android.app.Fragment.onDestroy(Fragment.java:1381)
at com.radioalmacristiana.BT_fragment.onDestroy(BT_fragment.java:224)
at com.radioalmacristiana.Cp_stream.onDestroyOptionsMenu(Cp_stream.java:388)
at android.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1948)
at android.app.Activity.onCreatePanelMenu(Activity.java:2647)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:512)
at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:881)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:297)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:812)
at android.view.Choreographer.doCallbacks(Choreographer.java:612)
at android.view.Choreographer.doFrame(Choreographer.java:581)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:798)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
02/28/15 02:54 PM (3 years ago)
What's the code in bt_fragment.java on line 224
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
02/28/15 02:55 PM (3 years ago)
What's the code on line 338 in cp_stream.java
 
g1pro757
Android Fan
Profile
Posts: 12
Reg: Feb 12, 2015
new york
120
like
02/28/15 03:26 PM (3 years ago)
BT_fragment.java line 224-
super.onDestroy();
Cp_stream.java line 338-
super.onDestroy();
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
02/28/15 03:34 PM (3 years ago)
Did you add any code?

Try Project> clean
 
g1pro757
Android Fan
Profile
Posts: 12
Reg: Feb 12, 2015
new york
120
like
02/28/15 03:37 PM (3 years ago)
The output on the console before the error I typed at the beginning of the post is this

02-28 17:27:36.716 28624-28624/com.radioalmacristiana W/ZZ? BT_activity_host:onBackPressed
02-28 17:27:36.716 28624-28624/com.radioalmacristiana W/ZZ? BT_screen_menuListSimple:onCreateOptionsMenu JSON itemId: "942E1C45BCB7C95B68E7F94"
02-28 17:27:36.716 28624-28624/com.radioalmacristiana W/ZZ? BT_screen_menuListSimple:onCreateOptionsMenu JSON itemId: "942E1C45BCB7C95B68E7F94" itemType: "BT_screen_menuListSimple" itemNickname: "Home Screen Menu"
02-28 17:27:36.716 28624-28624/com.radioalmacristiana W/ZZ? Cp_stream:onPause JSON itemId: "F6068B60A0D1525AE55F5E6" itemType: "Cp_stream" itemNickname: "Radio Stream"
02-28 17:27:36.716 28624-28624/com.radioalmacristiana D/AndroidRuntime? Shutting down VM
02-28 17:27:36.716 28624-28624/com.radioalmacristiana W/dalvikvm? threadid=1: thread exiting with uncaught exception (group=0x41720c08)



cleaning did not work by the way
I can press the back button on the nav bar but the physical android back button causes this.
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
02/28/15 04:53 PM (3 years ago)
The "back button" on the "nav bar"(action bar) is really a button to go to home screen as it won't go to previous screen.the home screen is probably the screen before the radio screen, which may give it that illusion.it's different from the hardware back button.

Are you using a emulator?
 
g1pro757
Android Fan
Profile
Posts: 12
Reg: Feb 12, 2015
new york
120
like
02/28/15 04:56 PM (3 years ago)
No I am using a physical device. I would like it to actually go back instead of crashing and ive tried different things but i end up going back to the way it originally was.
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
02/28/15 05:20 PM (3 years ago)
duplicate post
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
02/28/15 05:26 PM (3 years ago)
did you add some code? I dont see the onDestroy() method in the cp_stream class. The logcat you posted says the error is on line 388 of CP_Stream.java but there are only 387 lines.Looks like you added a method called onDestroyOptionsMenu()
 
g1pro757
Android Fan
Profile
Posts: 12
Reg: Feb 12, 2015
new york
120
like
02/28/15 06:28 PM (3 years ago)
Well I commented that out and it seems to work. Thank you! I was having some trouble with stopping the stream so I added that. I forgot it didnt come with the plugin/I didnt think that could be the problem.
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
02/28/15 06:30 PM (3 years ago)
Nice!yea that method is just for action bar menu items.glad you got it working
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
02/28/15 06:32 PM (3 years ago)
I know the problem you are mentioning about it not stopping. It changes back to the play button when you go back to the screen after you have left it.this cold be fixed with shared preferences or sqlite
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.