Android编程[新波士顿教程第27期]

时间:2014-07-15 15:55:21

标签: android

我从新的波士顿教程中学习了android编程,而且我在27号教程中遇到了困难。

当我尝试打开startplay活动时,它不会打开。该程序关闭说应用程序停止响应。

我已经尝试了所有可能的调整,但它仍然无效。

过去两天我一直坚持这个/

Manifest.xml是:

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >


    <activity
        android:name=".Splash"
        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=".StartingPoint"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.thenewboston.STARTINGPOINT" />

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

     <activity
       android:name=".Menu"
       android:label="@string/app_name" >
        <intent-filter>
           <action android:name="com.example.thenewboston.MENU" />
            <category android:name="android.intent.category.DEFAULT" />
       </intent-filter>
       </activity>  

        <activity
       android:name=".TextpLay"
       android:label="@string/app_name" >
        <intent-filter>
           <action android:name="com.example.thenewboston.Textplay" />
        </intent-filter>
       </activity>  

</application>

</manifest>

menu是:

package com.example.thenewboston;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;

import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Menu extends ListActivity{

    String classes[]= {"StartingPoint","Textplay","example2","example3","example4","example5","example6"};

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));


        }

        @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {
            // TODO Auto-generated method stub
            super.onListItemClick(l, v, position, id);
            String cheese=classes[position];
            try{
            Class<?> ourClass= Class.forName("com.example.thenewboston."+ cheese);
            Intent ourIntent= new Intent(Menu.this, ourClass);
            startActivity(ourIntent);
            }
            catch(ClassNotFoundException e){
                e.printStackTrace();
            }

        }

}

堆栈跟踪或logcat输出是:

07-15 19:04:56.508: W/dalvikvm(572): threadid=1: thread exiting with uncaught exception (group=0x409961f8)
07-15 19:04:56.558: E/AndroidRuntime(572): FATAL EXCEPTION: main
07-15 19:04:56.558: E/AndroidRuntime(572): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.thenewboston/com.example.thenewboston.Textplay}; have you declared this activity in your AndroidManifest.xml?
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.app.Activity.startActivityForResult(Activity.java:3190)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.app.Activity.startActivity(Activity.java:3297)
07-15 19:04:56.558: E/AndroidRuntime(572):  at com.example.thenewboston.Menu.onListItemClick(Menu.java:30)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.widget.AdapterView.performItemClick(AdapterView.java:292)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.widget.AbsListView$1.run(AbsListView.java:3168)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.os.Handler.handleCallback(Handler.java:605)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.os.Looper.loop(Looper.java:137)
07-15 19:04:56.558: E/AndroidRuntime(572):  at android.app.ActivityThread.main(ActivityThread.java:4340)
07-15 19:04:56.558: E/AndroidRuntime(572):  at java.lang.reflect.Method.invokeNative(Native Method)
07-15 19:04:56.558: E/AndroidRuntime(572):  at java.lang.reflect.Method.invoke(Method.java:511)
07-15 19:04:56.558: E/AndroidRuntime(572):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-15 19:04:56.558: E/AndroidRuntime(572):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-15 19:04:56.558: E/AndroidRuntime(572):  at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

如果您阅读了logcat输出,您会注意到这一行:

07-15 19:04:56.558: E/AndroidRuntime(572): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.thenewboston/com.example.thenewboston.Textplay}; have you declared this activity in your AndroidManifest.xml?

这表示它认为您尚未将Textplay活动添加到AndroidManifest.xml文件中。

查看您发布的AndroidManifest,看起来您放入了TextpLay而不是Textplay

   <activity
   android:name=".TextpLay"
   android:label="@string/app_name" >