samedi 16 mai 2015

Error in starting new activity using Intent in android

I have created a menu for my android application. The menu has several buttons, The first buttons should start new Activity called "BackgroundImages" using Intent. However, When I install the app on the emulator and click the button, I receive the following error "Unfortunatlry, NewtonLow has stopped".Moreover, "NewtonLow" is the name of the application. The following demonstrates the steps I did in order to start new Activity.

  1. I created a class called Menu which display the the menu.xml layout as follows:

    public class Menu extends Activity{
    
       MediaPlayer mp1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);  
        mp1= MediaPlayer.create(this,R.raw.button );
        Button but1 =  (Button)findViewById(R.id.button1);
        but1.setOnClickListener(new View.OnClickListener() {            
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                mp1.start();
                startActivity(new Intent("ghassar.mohamed.newtonlaw.BACKGROUNDIMAGES"));
            }
        });
    }}
    
    
  2. I have edited the Manifast to launch the menu class first as follows:

        <activity
        android:name=".Menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    
    
    1. I have also added activity for the backgroundImage class to use it so I can I can start the activity :

              <activity android:name=".BackgroundImages"android:label="@string/app_name" >
      <intent-filter>
          <action android:name="ghassar.mohamed.newtonlaw.BACKGROUNDIMAGES" />
          <category android:name="android.intent.category.DEFUALT" />
      </intent-filter>
      
      

Aucun commentaire:

Enregistrer un commentaire