And, that worked like a charm. Not obvious. I like this book. Definitely a good guide, but they DO leave some important details out here and there.
On May 11, 8:33 am, Carmen Delessio <carmendeles...@gmail.com> wrote: > I experienced something like this when following the example in the book. > The Author's have code and a comment on this > here:http://unlocking-android.googlecode.com/svn/chapter3/trunk/Restaurant... > > The key to this, I think, is the AndroidManifest.xml > file:http://unlocking-android.googlecode.com/svn/chapter3/trunk/Restaurant... > > <application android:icon="@drawable/restaurant_icon" > android:label="@string/app_short_name" > android:name="RestaurantFinderApplication" > android:allowClearUserData="true" > android:theme="@android:style/Theme.Black"> > ... > > When using this method, you *must* specify the "android:name" for the > application and it needs to be the name of the application class. > > In the specific case described, check AndroidManifest.xml and, if it is not > there, add android:name="BoardGamerFinderApplication" > > More info on > this:http://developer.android.com/intl/zh-CN/guide/appendix/faq/framework.... > > Carmen > -- > Carmen > Delessiohttp://www.twitter.com/CarmenDelessiohttp://www.talkingandroid.comhttp://www.facebook.com/BFFPhotohttp://www.twitter.com/DroidDrop > > > > On Tue, May 11, 2010 at 11:13 AM, Jon Jacob <jonjacobm...@gmail.com> wrote: > > 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 <janderson....@gmail.com> 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 <jonjacobm...@gmail.com> > > 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 > > > > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > > <android-beginners%2bunsubscr...@googlegroups.com<android-beginners%252bunsubscr...@googlegroups.com> > > > > > 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 > > > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > > > 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 > > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > > 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 > android-beginners+unsubscr...@googlegroups.com > 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 android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en