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

Apps Button Intent startActivity() HELP?!

I'm going to split this up into small pieces

(BTW, this is just a test app, because i wan't to know how to do stuff before making apps :)

My main.xml looks like this
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <Button
        android:id="@+id/nextpage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Go to next Page" />

</LinearLayout>

And the main.java i created for that looks like this

Code:
package com.danielholst.testing;

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

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button nextpage = (Button) findViewById(R.id.nextpage);
        nextpage.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
		        Intent aboutpage = new Intent("com.danielholst.testing.PAGETWO");
		        startActivity(aboutpage);
			}
		});
    }

	}

i've created 2 different activities, and an xml file for both of them,
but whenever i press the button, i get a force close message,
can anyone tell what i did wrong, and how to fix it.


here is my manifest

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.danielholst.testing"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Main"
            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=".page2"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.PAGETWO" />

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

</manifest>
 
The android:name attribute of an activity tag must match the name of the Activity class, exactly.

But you have a difference.

In your code you refer to the second page activity as PAGETWO.
Code:
Intent aboutpage
  = new Intent("com.danielholst.testing.[COLOR=RED]PAGETWO[/COLOR]");
startActivity(aboutpage);

In your AndroidManifest.xml you refer to the second page activity as page2.
Code:
<activity
  android:name=".[COLOR=RED]page2[/COLOR]"
[/QUOTE]

These both need to be the same and be exactly whatever you've name the actual Activity class.


BTW Whenever your application is forced closed, it's because of an unhandled exception.  This exception will be logged into the LogCat view of Eclipse.  This logged exception will help you (and us, so post it) to figure out what went wrong.
 
The android:name attribute of an activity tag must match the name of the Activity class, exactly.

But you have a difference.

In your code you refer to the second page activity as PAGETWO.


In your AndroidManifest.xml you refer to the second page activity as page2.


These both need to be the same and be exactly whatever you've name the actual Activity class.


BTW Whenever your application is forced closed, it's because of an unhandled exception. This exception will be logged into the LogCat view of Eclipse. This logged exception will help you (and us, so post it) to figure out what went wrong.


so if i make a new android project,
and make a new class called TestAppSecondPage
would i have to name it com.package.name.TestAppSecondPage in the manifest

thx again
 
Back
Top Bottom