• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problem launching activity from menu

cr5315

Android Enthusiast
I've been trying to figure out what is keeping the reason why the menu won't launch a new activity. All the other options in the menu work just fine, INCLUDING one that "reloads" the page by launching the main activity again and calling finish() on the first one. I'e tried every example on developer.android.com and many others online, but none of them have worked.
Eclipse is giving me this when I click on the menu option on my phone.
2w341sz.png

Here's the part of the code for the menu
Code:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.Reload:     
        	Intent reloadIntent = new Intent(this, AndroidRssReader.class);
        	startActivity(reloadIntent);
        	finish();
            break;
        case R.id.About:     
        	Intent myIntent = new Intent (this, About.class);
        	startActivity(myIntent);
            break;
        case R.id.Exit: 
        	finish();
            break;
    }
    return true;
}

menu.xml
Code:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/Reload"
		android:title="Reload"
		android:orderInCategory="1"	/>
	<item android:id="@+id/About"
		android:orderInCategory="2"
		android:title="About" />
<item android:id="@+id/Exit"
		android:orderInCategory="3"
		android:title="Exit" />
</menu>

And the activity I'm trying to launch
Code:
package com.bba.virusexperts;

import android.os.Bundle;

public class About extends AndroidRssReader {
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about);
	}

}
 
This is what I have in the manifest
Code:
<activity class=".About" android:name="About"></activity>
 
Is the <activity> entry in between the <application ....> </application> entries in the Mainfest?

Just a weird thought, but try adding to the name About like AboutMyApp since you also have your menu item named About. Remember you will also have to change the name of the file to AboutMyApp.java.
 
Still nothing after changing the activity name and making sure that the <activity> was in between the <application> tags
 
In your About class, you don't have the override:

public class About extends AndroidRssReader {
@Override
public void onCreate(Bundle savedInstanceState) {

I wonder if that's causing it.
 
I don't know why I didn't see this before. It's the space you have in your Intent declaration:
Intent myIntent = new Intent (this, About.class);
remove the space:
Intent myIntent = new Intent(this, About.class);
 
Then it's time to start putting in some logging to see whether it's the click and Intent firing not working, or if the About.class is not working properly. Look up the Log class:

import android.util.Log;

Then in your code place something like this:
Log.w(this.getClass().getName(), "The About button was clicked.");

It will show up in the DDMS portion of Eclipse. You can view all of the logs, and this will allow you to trace your code and see if it's the button click not working or the About.class code not working.
 
The logcat showed the the about button was clicked. So that means that the problem is in the about.class?
 
It also says "Starting activity: Intent {cmp=com.bba.virusexperts/.VirusAbout }"
right after the statement about the button being pressed.
 
I foxed the problem. I had the about class extending AndroidRssReader. I changed it to extend Activity and now it's working. Thanks for your help on all the other stuff.
 
Back
Top Bottom