0

How to open a new intent when there are spaces within the array (such as "Hello World") The class I'm trying to access is called startingPoint.

It gives me an error as there cannot be any spaces within the -> android:name=""

Is there any workaround?

Thanks in advance

Root.java

public class Root extends ListActivity {

String classes[] = { "Hello World", "Another Item", "Email"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setListAdapter(new ArrayAdapter<String>(Root.this,
            R.layout.root, classes));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String MENU_CHOICE = classes[position];
    try {
        Class ourClass = Class.forName("se.hello.visboken." + MENU_CHOICE);
        Intent ourIntent = new Intent(Root.this, ourClass);
        startActivity(ourIntent);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}
}

My manifest looks like this

    <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Root"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="se.hello.visboken.ROOT" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".startingPoint"
        android:label="Hello World" >
        <intent-filter>
            <action android:name="se.hello.visboken.startingPoint" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

1 Answer 1

0

In your case, the Activity you need to launch is startingPoint, not Hello World. Hello World is the title of that activity.


Update:

Create another string array of same size (must) but contains classes' names inside, not titles.

String tmp[] = { "startingPoint", "anotherClass1", "anotherClass2"};

and in onListItemClick, read it as below:

String MENU_CHOICE = tmp[position];
4
  • I still want the strings in the listactivity to be the ones presented on the screen and I want to fire the intent that is called in the manifest.
    – noxious
    May 8, 2012 at 18:40
  • then try replacing Hello World with startingPoint in String classes[]
    – waqaslam
    May 8, 2012 at 18:44
  • If I do that Hello World will not be shown as a listitem in the listactivity on the actual phone, I still want it to say "Hello World" there but I cannot launch an activity if it has spaces in it. Sorry if I were unclear at first.
    – noxious
    May 8, 2012 at 18:45
  • you simply cant launch an activity with space in its name. any how, see my updated answer.
    – waqaslam
    May 8, 2012 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.