getApplication(), I believe, comes from the Application class that BoardGameFinderApplication is an extension of. I did put the suspected section in a try - catch block and the error message referenced the android.app.Application as the error.... not very helpful since I pretty much know that is where the problem lies. I just don't know the specific cause.
On May 11, 7:46 am, Justin Anderson <[email protected]> wrote: > Where is the getApplication() method defined? My initial thought would be > that it is returning null for some reason and you are not checking for > that... perhaps with a try catch block or a simple null check... But I can't > tell for sure without seeing this method. > > What does logcat say about the cause? > > Thanks, > Justin > > ---------------------------------------------------------------------- > There are only 10 types of people in the world... > Those who know binary and those who don't. > ---------------------------------------------------------------------- > > > > On Tue, May 11, 2010 at 8: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 at > >http://stackoverflow.com/questions/tagged/android > > > To unsubscribe from this group, send email to > > [email protected]<android-beginners%[email protected]> > > For more options, visit this group at > >http://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 > 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

