"Unlocking Android" is a good book, but I have learned from my own experience with it that it is not a good idea to type in code from the text and expect it to work. Much better to get the code from the book's website and run that. Download it from the website, compare that to what you already have, and it will mostly likely simply work.
If you are still having trouble with it, there is a Manning forum for the book too. In my experience, some one of the authors will usually respond promptly and helpfully. On May 11, 7:02 am, Jon Jacob <[email protected]> wrote: > I am a newbie both to Java and Android and have been reading the book > "Unlocking Android" and trying to learn by adapting their code to my > ideas for a project to play with and learn Android. > > But, I have run into a brick wall that I need help with. The > following code gives me a force close when I click the submit button, > and I don't know why. (Good debugging tips would be nice too.) > > Its the line: > > BoardGameFinderApplication application = (BoardGameFinderApplication) > getApplication(); > > that seems to be causing the crash. I just don't understand why? All > indications are that I am using it correctly. What am I missing? > > Here is the code: > > From my main activity class: > > import java.util.ArrayList; > > import android.app.Activity; > import android.content.Intent; > import android.os.Bundle; > import android.os.Debug; > import android.view.View; > import android.view.View.OnClickListener; > import android.widget.Button; > import android.widget.EditText; > import android.widget.TextView; > > public class BoardgameCriteria1 extends Activity { > > private Button grabGames; > private TextView introText; > private EditText gameName; > ArrayList<String> bglNames = new ArrayList<String>(); > private String s; > > @Override > public void onCreate(Bundle icicle) { > super.onCreate(icicle); > > setContentView(R.layout.main); > this.introText = (TextView) findViewById(R.id.IntroText); > this.gameName = (EditText) findViewById(R.id.GameName); > this.grabGames = (Button) findViewById(R.id.Submit); > > // get the board game names when submit button hit > this.grabGames.setOnClickListener( > new OnClickListener() { > public void onClick(View v) { > handleGetReviews(); > } > }); > } > > private void handleGetReviews() { > > BoardGameFinderApplication application = > (BoardGameFinderApplication) getApplication(); > > application.setBoardGameCriteriaName(this.gameName.getText().toString()); > Intent intent = new Intent(this.getApplicationContext(), > GameList1.class); > startActivity(intent); > } > > } > > .... and the BoardGameFinderApplication class: > > public class BoardGameFinderApplication extends Application { > > private BoardGame currentBoardGame; > private String gameCriteriaName; > > public BoardGameFinderApplication() { > super(); > } > > @Override > public void onCreate() { > super.onCreate(); > } > > @Override > public void onTerminate() { > super.onTerminate(); > } > > public BoardGame getCurrentBoardGame() { > return this.currentBoardGame; > } > > public String getBoardGameCriteriaName() { > return this.gameCriteriaName; > } > > public void setCurrentBoardGame(BoardGame currentBoardGame) { > this.currentBoardGame = currentBoardGame; > } > > public void setBoardGameCriteriaName(String boardGameCriteriaName) > { > this.gameCriteriaName = boardGameCriteriaName; > } > > } > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > > NEW! Try asking and tagging your question on Stack Overflow > athttp://stackoverflow.com/questions/tagged/android > > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group > athttp://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en

