1. Are you ready for the Galaxy S20? Here is everything we know so far!

Apps Problem launching activity from menu

Discussion in 'Android Development' started by cr5315, Feb 16, 2011.

  1. cr5315

    cr5315 Android Enthusiast
    Thread Starter

    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.
    [​IMG]
    Here's the part of the code for the menu
    Code (Text):
    1. @Override
    2. public boolean onCreateOptionsMenu(Menu menu) {
    3.     MenuInflater inflater = getMenuInflater();
    4.     inflater.inflate(R.menu.menu, menu);
    5.     return true;
    6. }
    7. @Override
    8. public boolean onOptionsItemSelected(MenuItem item) {
    9.     switch (item.getItemId()) {
    10.         case R.id.Reload:    
    11.             Intent reloadIntent = new Intent(this, AndroidRssReader.class);
    12.             startActivity(reloadIntent);
    13.             finish();
    14.             break;
    15.         case R.id.About:    
    16.             Intent myIntent = new Intent (this, About.class);
    17.             startActivity(myIntent);
    18.             break;
    19.         case R.id.Exit:
    20.             finish();
    21.             break;
    22.     }
    23.     return true;
    24. }
    menu.xml
    Code (Text):
    1. <menu xmlns:android="http://schemas.android.com/apk/res/android">
    2. <item android:id="@+id/Reload"
    3.         android:title="Reload"
    4.         android:orderInCategory="1" />
    5.     <item android:id="@+id/About"
    6.         android:orderInCategory="2"
    7.         android:title="About" />
    8. <item android:id="@+id/Exit"
    9.         android:orderInCategory="3"
    10.         android:title="Exit" />
    11. </menu>
    12.  
    And the activity I'm trying to launch
    Code (Text):
    1. package com.bba.virusexperts;
    2.  
    3. import android.os.Bundle;
    4.  
    5. public class About extends AndroidRssReader {
    6.    
    7.     public void onCreate(Bundle savedInstanceState) {
    8.         super.onCreate(savedInstanceState);
    9.         setContentView(R.layout.about);
    10.     }
    11.  
    12. }
     

    Advertisement

  2. cr5315

    cr5315 Android Enthusiast
    Thread Starter

    This is what I have in the manifest
    Code (Text):
    1. <activity class=".About" android:name="About"></activity>
     
  3. idavis

    idavis Newbie

    I think your manifest might just need to have this:
    <activity android:name="About"></activity>

    See if that works.
     
  4. cr5315

    cr5315 Android Enthusiast
    Thread Starter

    I put that in and it didn't work. Same errors as the last times.
     
  5. idavis

    idavis Newbie

    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.
     
  6. cr5315

    cr5315 Android Enthusiast
    Thread Starter

    Still nothing after changing the activity name and making sure that the <activity> was in between the <application> tags
     
  7. idavis

    idavis Newbie

    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.
     
  8. cr5315

    cr5315 Android Enthusiast
    Thread Starter

    Same errors
     
  9. idavis

    idavis Newbie

    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);
     
  10. cr5315

    cr5315 Android Enthusiast
    Thread Starter

    It's not the space. Still the same problems.
     
  11. idavis

    idavis Newbie

    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.
     
    cr5315 likes this.
  12. cr5315

    cr5315 Android Enthusiast
    Thread Starter

    The logcat showed the the about button was clicked. So that means that the problem is in the about.class?
     
  13. cr5315

    cr5315 Android Enthusiast
    Thread Starter

    It also says "Starting activity: Intent {cmp=com.bba.virusexperts/.VirusAbout }"
    right after the statement about the button being pressed.
     
  14. cr5315

    cr5315 Android Enthusiast
    Thread Starter

    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.
     
Loading...
Similar Threads - Problem launching activity
  1. Spyros_B
    Replies:
    7
    Views:
    257
  2. JAMES31055
    Replies:
    1
    Views:
    197
  3. Rob
    Replies:
    11
    Views:
    82
  4. radimtr
    Replies:
    3
    Views:
    200
  5. KevinDP
    Replies:
    0
    Views:
    253
  6. Kishor Bapat
    Replies:
    1
    Views:
    161
  7. train7740
    Replies:
    1
    Views:
    126
  8. Timoth
    Replies:
    3
    Views:
    156
  9. Rgarner
    Replies:
    38
    Views:
    914
  10. moppliger1
    Replies:
    8
    Views:
    291

Share This Page

Loading...