Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › android application debugging (restarting game)
New Posts  All Forums:Forum Nav:

android application debugging (restarting game)

post #1 of 6
Thread Starter 
Hi guys, I'm working on my first android application, a simple yahtzee game. Currently I'm trying to restart my game by clicking a play again button. I've switched views (gameover.xml) and have the onclick in the xml point to a playagain funtion.

I've kind of got two questions regarding this, first would be that even with an empty method the button causes the application to crash. I'm not exactly sure why. The second is what would be the best method for restarting my game? I was thinking that restarting the activity would be the easiest way but I'm open to other suggestions. Below is the xml code for my play again button:
Code:
<Button
android:id="@+id/playbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play Again"
android:layout_weight="1"
android:onClick="playagain"
>
</Button>
I've tried a couple of different methods for restarting my game but haven't been able to test if they work because my app keeps crashing as soon as the button is pressed. In case I've got something setup incorrectly here's the empty playagain function:
Code:
private void playagain(){
}

Any help is much appreciated.
post #2 of 6
You forgot to post your debug log.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #3 of 6
Thread Starter 
Here's what logcat showed
Code:
I/ActivityManager(   60): Start proc org.paceacademy for activity org.paceacademy/.YahtzeeMain: pid=340 uid=10034 gids={1015}
I/ARMAssembler(   60): generated scanline__00000177:03515104_00001002_00000000 [ 87 ipp] (110 ins) at [0x4446d6f0:0x4446d8a8] in 1043000 ns
D/dalvikvm(  340): GC_EXTERNAL_ALLOC freed 66K, 52% free 2621K/5379K, external 976K/1038K, paused 72ms
I/ActivityManager(   60): Displayed org.paceacademy/.YahtzeeMain: +2s512ms
D/dalvikvm(  340): GC_EXTERNAL_ALLOC freed 19K, 51% free 2653K/5379K, external 1496K/1575K, paused 43ms
D/dalvikvm(  340): GC_EXTERNAL_ALLOC freed 18K, 51% free 2670K/5379K, external 1670K/1922K, paused 51ms
D/AndroidRuntime(  340): Shutting down VM
W/dalvikvm(  340): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime(  340): FATAL EXCEPTION: main
E/AndroidRuntime(  340): java.lang.IllegalStateException: Could not find a method playagain(View) in the activity class org.paceacademy.YahtzeeMain for onClick handler on view class android.widget.Button with id 'playbutton'
E/AndroidRuntime(  340): at android.view.View$1.onClick(View.java:2131)
E/AndroidRuntime(  340): at android.view.View.performClick(View.java:2485)
E/AndroidRuntime(  340): at android.view.View$PerformClick.run(View.java:9080)
E/AndroidRuntime(  340): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime(  340): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(  340): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  340): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(  340): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  340): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(  340): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(  340): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(  340): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  340): Caused by: java.lang.NoSuchMethodException: playagain
E/AndroidRuntime(  340): at java.lang.ClassCache.findMethodByName(ClassCache.java:247)
E/AndroidRuntime(  340): at java.lang.Class.getMethod(Class.java:962)
E/AndroidRuntime(  340): at android.view.View$1.onClick(View.java:2124)
E/AndroidRuntime(  340): ... 11 more
W/ActivityManager(   60):   Force finishing activity org.paceacademy/.YahtzeeMain
W/ActivityManager(   60): Activity pause timeout for HistoryRecord{405742b0 org.paceacademy/.YahtzeeMain}
W/ActivityManager(   60): Activity destroy timeout for HistoryRecord{405742b0 org.paceacademy/.YahtzeeMain}

post #4 of 6
Thread Starter 
I managed to fix the program by changing the method to public and passing in View x. I managed to restart my activity by running:
Code:
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
post #5 of 6
Just restarting the activity seems like the most reasonable thing to do. smile.gif
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #6 of 6
Thread Starter 
Quote:
Originally Posted by error10;12637565 
Just restarting the activity seems like the most reasonable thing to do. smile.gif

Yeah that was my reasoning, I just couldn't get the thing to stop crashing before! Kind of a dumb mistake on my part but I'm still learning so it's all good tongue.gif
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › android application debugging (restarting game)