0

I have two different activities in my android applications. The first(MainActivity) has ImageButton through which onClick it's getting navigate two second activity(Numbers). This is my code of MainActivity

package com.android.learning_numbers;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.ImageButton;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {

    ImageButton imageButton;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        addListenerOnButton();
    }

public void addListenerOnButton() {
        imageButton = (ImageButton) findViewById(R.id.button1);
        imageButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(MainActivity.this, Numbers.class);
                    startActivity(intent); 
            }
        });
    }

}

Now here there is no error in error log but when application is getting launched on click of imagebutton it is getting crashed. & showing error in LogCat. What i do now. Please help..

SuRaj Creator
  • 945
  • 1
  • 9
  • 25

3 Answers3

1

It would seem that you haven't declared the Numbers Activity in the Android Manifest. If an Activity is not declared in the Manifest, as far as the application is concerned, the Activity does not exist which causes the application to crash.

<application>
    <activity
        android:name="com.android.learning_numbers.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.android.learning_numbers.Numbers"/>
</application>
W.K.S
  • 9,787
  • 15
  • 75
  • 122
0

Try this.. in your manifest before </application>

 <activity 
        android:name="com.android.learning_numbers.MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
 </activity>
 <activity
        android:name=".Numbers" />
Hariharan
  • 24,741
  • 6
  • 50
  • 54
0
<activity
            android:name="com.android.learning_numbers.Numbers"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar"
            android:windowSoftInputMode="adjustResize" >
Venkatesh S
  • 5,466
  • 1
  • 25
  • 30