Intent CRASH的Android启动活动

时间:2014-07-29 11:04:44

标签: android android-intent

在下面这个简单的Android应用程序中点击动作栏菜单项,如aboutMe我想开始新的活动。创建了对新活动和类的意图,但在单击show about活动的项目后,我的应用程序崩溃。

错误:

Unfortuanetly Hadith, has stopped

MainActivity类:

package com.example.Hadis;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.abouteMe) {
            Intent intent = new Intent(MyActivity.this,AboutMe.class);
            startActivity(intent);
        }
        return super.onOptionsItemSelected(item);
    }
}

关于我的课程:

package com.example.Hadis;

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

/**
 * Created by tux-world on 7/29/14.
 */
public class AboutMe extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);
    }
}

about.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="New Text"
            android:id="@+id/textView"/>
</LinearLayout>

menu.xml文件:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      tools:context=".MyActivity" >
    <item android:id="@+id/action_search"
          android:icon="@drawable/ic_action_search"
          android:title="@string/action_search"
          android:showAsAction="ifRoom|collapseActionView"
          android:actionViewClass="android.widget.SearchView" />


    <item android:id="@+id/my_action"
          android:icon="@drawable/ic_action_edit"
          android:hint="@string/your_mind"
          android:textColorHint="@android:color/white"
          android:title="@string/action_search"
          android:showAsAction="ifRoom|collapseActionView"
          android:actionLayout="@layout/my_action" />

    <item android:id="@+id/action_settings"
          android:title="@string/action_settings"
          android:icon="@android:drawable/ic_menu_help"
          android:showAsAction="ifRoom|collapseActionView" />

    <item android:id="@+id/abouteMe"
          android:title="@string/action_settings"
          android:orderInCategory="100" />
</menu>

1 个答案:

答案 0 :(得分:2)

您必须声明您的AboutMe活动

    <activity android:name=".AboutMe"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>