[android-beginners] Re: Force Close when trying to use getApplication()

2010-05-11 Thread Jon Jacob
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  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...
>
>          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  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  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 
> > 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 bglNames = new ArrayList();
> > > >        private String s;
>
> > > >   �...@override
> > > >    public void onCreate(Bundle icicle) {
> > > >        super.onCreate(icicle);
>
> > > >        setContentView(R.layout.main);
> > > >        this.introText = (TextView) findViewById(R.id.IntroText)

[android-beginners] Re: Force Close when trying to use getApplication()

2010-05-11 Thread Jon Jacob
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  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  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 bglNames = new ArrayList();
> >        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)
> > {
&

[android-beginners] Force Close when trying to use getApplication()

2010-05-11 Thread Jon Jacob
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 bglNames = new ArrayList();
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
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en


[android-beginners] Re: How to create a new folder on the SD card?

2010-05-07 Thread Jon Jacob
You hate finding the answer  ;)

This is good to know, anyway.  Thanks for posting the answer.

On May 6, 4:56 pm, DonFrench  wrote:
> I hate it when I find the answer two minutes after posting the
> question!   All I needed was this:
>
>  android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
>
> in the manifest.
>
> On May 6, 4:50 pm, DonFrench  wrote:
>
>
>
> > I am not succeeding in creating a new folder on the SD card using the
> > following code:
>
> >   try{
> >     String dirName = "/sdcard/testdir";
> >     File newFile = new File(dirName);
> >     newFile.mkdirs();
> >     if(newFile.exists()){
> >         toastLong("directory exists");
> >         if(newFile.isDirectory()){
> >                 toastLong("isDirectory = true");
> >         } else toastLong("isDirectory = false");
> >     } else {
> >         toastLong("directory doesn't exist");
> >     }} catch(Exception e){
>
> >         toastLong("Exception creating folder " + e);
>
> > }
>
> > I don't get an exception but the message I do get is "directory
> > doesn't exist"and in fact the folder is not created.  Why doesn't this
> > work and what is the right way to do this?
>
> > --
> > 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 
> 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