1

我正在尝试使用意图开始新活动,但它永远不会起作用。

两项活动

  1. MainActivity.java
  2. 播放.java

两种布局

  1. activity_main.xml
  2. 布局播放.xml

它显示 THE APPLICATION HAS STOPPED UNEXPECTEDLY 错误在哪里?

MainActivity.java

package com.example.xxx;



import android.os.Bundle;  
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener{


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

    Typeface t= Typeface.createFromAsset(getAssets(), "font.ttf");

    TextView tv1= (TextView) findViewById(R.id.textView1);
    tv1.setTypeface(t);
    tv1.setOnClickListener(this);


}

@Override
public void onClick(View v) {

    if(v.getId()==R.id.textView1){

        Intent i=new Intent(MainActivity.this,Play.class);

        MainActivity.this.startActivity(i);

    }
       }    
}

播放.java

package com.example.xxx;

import android.os.Bundle;  
import android.app.Activity;


    public class Play extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layoutplay);
}  
   }

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

  <ImageView
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:layout_alignParentLeft="true"
   android:src="@drawable/bouncemenuback" 
   android:contentDescription="@string/menuback"  />

  <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_margin="10dp"
      android:orientation="vertical" >

      <TextView
       android:id="@+id/textView1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center"
       style="@style/my"
       android:text="@string/Play"/>
     </LinearLayout>

     </RelativeLayout>

布局播放.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Play" >

</RelativeLayout>

xxx.manifest

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

   <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="9" />

   <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.xxx.MainActivity"
        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="com.example.xxx.Play"
        android:label="@string/title_activity_play" >
         />

    </activity>
   </application>

 </manifest>
4

2 回答 2

1

尝试删除未使用 的/>内部 <activity android:name="com.example.xxx.Play" ..... > /> </activity>AndroidManifest.xml

所以你的代码应该是:

<activity
        android:name="com.example.xxx.Play"
        android:label="@string/title_activity_play" >
    </activity>
于 2013-08-18T11:54:57.017 回答
0

尝试用以下代码替换您的清单代码:

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

   <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="9" />

   <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.xxx.MainActivity"
        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="com.example.xxx.Play"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.PLAY" />

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

 </manifest>

希望这可以帮助 :)

于 2013-08-18T17:35:54.103 回答