I'm just learning how to program for android and am trying to work through Ed Burnette's Hello, Android book (ed. 3, so newest version).
At the end of chap. 4 here, just following the code in the book (which I tried to copy with a few presumably innocuous changes so as to lear how it works) gives me a decent Sudoku game on the Eclipse emulator.
Here's my problem: The games work as they should when I choose easy or difficult, but when I choose Medium difficulty, the emulator says "The application Sudoku (process org.example.sudoku) has stopped unexpectedly. Please try again" and a "Force close" button that closes the application.
There's quite a bit of code here, and, since everything works fine so far for easy or hard, I'm assuming that somewhere along the way there's a typo that's not matching something up. But at least this looks right to me:
[/LEFT]
At the end of chap. 4 here, just following the code in the book (which I tried to copy with a few presumably innocuous changes so as to lear how it works) gives me a decent Sudoku game on the Eclipse emulator.
Here's my problem: The games work as they should when I choose easy or difficult, but when I choose Medium difficulty, the emulator says "The application Sudoku (process org.example.sudoku) has stopped unexpectedly. Please try again" and a "Force close" button that closes the application.
There's quite a bit of code here, and, since everything works fine so far for easy or hard, I'm assuming that somewhere along the way there's a typo that's not matching something up. But at least this looks right to me:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Game [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Activity {[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] String [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TAG[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2] = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Sudoku"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] String [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]KEY_DIFFICULTY[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2] = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"org.example.sudoku.difficulty"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DIFFICULTY_EASY[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2] = 0;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DIFFICULTY_MEDIUM[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2] = 1;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DIFFICULTY_HARD[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2] = 2;[/SIZE]
[SIZE=2]...[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
So, I look in LogCat and find this (after trying to start a medium difficulty game):
Sudoku Clicked on 1
ActivityManager Starting Activity: Intent {...}
Sudoku onCreate
AndroidRuntime Shutting down VM
dalvikvm threadid=1: thread exiting with uncaught exception (group=0x4001d800)
AndroidRuntime FATAL EXCEPTION: main
...
Sudoku Clicked on 1
ActivityManager Starting Activity: Intent {...}
Sudoku onCreate
AndroidRuntime Shutting down VM
dalvikvm threadid=1: thread exiting with uncaught exception (group=0x4001d800)
AndroidRuntime FATAL EXCEPTION: main
...
But when I click on Easy difficulty level, I get
Sudoku Clicked on 0
ActivityManager Starting Activity: Intent { ...}
Sudoku onCreate
Sudoku used[0][0] = 4568
...
Sudoku Clicked on 0
ActivityManager Starting Activity: Intent { ...}
Sudoku onCreate
Sudoku used[0][0] = 4568
...
So, that isolates it to something that happens after onCreate() is called, right? Moreover, the logging of "Clicked on 0" (or 1) happens in the startGame() method, still in Sudoku.java. Here's that method:
Code:
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] startGame([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] i) {[/SIZE]
[LEFT][SIZE=2]Log.[I]d[/I]([/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TAG[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"clicked on "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + i);[/SIZE]
[SIZE=2]Intent intent = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Intent([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], Game.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE]
[SIZE=2]intent.putExtra(Game.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]KEY_DIFFICULTY[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], i);[/SIZE]
[SIZE=2]startActivity(intent);[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]
So, up to there we should be ok.
Now, when I try to use the debugger (with breakpoint on the startActivity(intent) line in startGame()) to determine what's going on, this is what happens:
1) a bunch of stuff that looks ok comes up, so step into with F5
2) Now I get in Activity.class Source not found. "The JAR file C:\android-sdk-windows\platforms\android-8\android.jar has no source attachment.
1) a bunch of stuff that looks ok comes up, so step into with F5
2) Now I get in Activity.class Source not found. "The JAR file C:\android-sdk-windows\platforms\android-8\android.jar has no source attachment.
Unfortunately, when I debug and use easy level of difficulty, the debugger does exactly the same thing.
So, I'm a bit at a loss as to where to look to see what the problem is. Any ideas?
[/LEFT]