0

I have been reading the first answer here to setup a class to hold my global variables. I have created the following class within my applications java file, my main activity follows it:

class GlobalStore extends Application {

    String str;

}

public class todo extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        GlobalStore appState = (GlobalStore) getApplicationContext();
        String tmpstr = appState.str;
    }
}

My manifest.xml file has the following tag:

<application android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:name="GlobalStore">

I'm pretty sure I followed the instructions correctly however my app force closes when it starts. Hopefully someone can point out what I have done wrong as I can't work it out. Thanks.

Community
  • 1
  • 1
Crazyfool
  • 2,719
  • 3
  • 16
  • 5

2 Answers2

2

Your are missing a dot.

It should be .GlobalStore as long as this class resides in the package set in the package attribute on the manifest node.

So it should look like this.

<application android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:name=".GlobalStore">
Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
0
android:name="GlobalStore"

This needs to be the full path including your package. ie

android:name="com.example.GlobalStore"

or whatever your package name is.

Falmarri
  • 47,727
  • 41
  • 151
  • 191
  • Well, that's not true. You can use, for instance, `android:name=".App"` ;) -1! When you edit it I will remove my downvote! haha just kidding... don't like downvotes XD Btw, I'm not kidding about the `.App` stuff. – Cristian Feb 03 '11 at 20:24
  • You can't do that for the application node. You can do that for activity nodes but the application one has to be a full path. – Falmarri Feb 04 '11 at 04:14
  • I have tried both using the .GlobalStore and fullpath.globalstore but still getting fc's – Crazyfool Feb 04 '11 at 12:02
  • @Crazyfool: So post your logcat – Falmarri Feb 04 '11 at 16:29
  • @falmarri sorry for the late response. Have you tried something like .AppName instead of the full path? I think you haven't because it works. If you are still in doubt I can prepare an example for you to learn from it :) – Cristian Feb 05 '11 at 18:07
  • @Cristian: Maybe I have something confused, or something changed, because I thought it used to require that. I know there are cases where you need the full path. But I'm not sure what those are now. – Falmarri Feb 05 '11 at 22:49
  • @Falmarri: I think it is only when you use library components having another package path than your projects. – Octavian Helm Feb 06 '11 at 17:16