由于启动资产 activity 的 activity 启动导致应用程序崩溃

App Crash due to start of activity that launches asset activity

我正处于学习阶段,我正在构建一个应用程序来测试系统活动。这是主要代码 activity:

public class MainActivity extends ListActivity {

String tests[] = { "LifeCycleTest", "SingleTouchTest", "MultiTouchTest",
        "KeyTest", "AccelerometerTest", "AssetsTest",
        "ExternalStorageTest", "SoundPoolTest", "MediaPlayerTest",
        "FullScreenTest", "RenderViewTest", "ShapeTest", "BitmapTest",
        "FontTest", "SurfaceViewTest" };

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<>(this,
            android.R.layout.simple_list_item_1, tests));
}

@Override
protected void onListItemClick(ListView list, View view, int position, long id) {
    super.onListItemClick(list, view, position, id);
    String testName = tests[position];
    try {
        Class c = Class.forName("com.ag.systemtests." + testName);
        Intent intent = new Intent(this, c);
        startActivity(intent);
    } catch (ClassNotFoundException e) {  e.printStackTrace();  }
}
}

当我 运行 应用程序时,它 运行 没问题,直到我选择 AssestsTest 选项。 activity AssetsTest 的代码是:

import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.widget.TextView;

public class AssetsTest extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        TextView textView = new TextView(this);
        setContentView(textView);

        AssetManager assetManager = getAssets();


        InputStream input;
        try {
            input = assetManager.open("myawesometext.txt");

            int size = input.available();
            byte[] buffer = new byte[size];
            input.read(buffer);
            input.close();

            // byte buffer into a string
            String text = new String(buffer);

            textView.setText(text);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

当我选择这个 activity 时,应用程序崩溃了。错误出现在 startActivity(intent) 行。我该怎么办?

logcat是:

10-03 00:15:59.186  24699-24699/com.androidgames.systemtests I/art﹕ Late-enabling -Xcheck:jni
10-03 00:15:59.232  24699-24710/com.androidgames.systemtests I/art﹕ Debugger is no longer active
10-03 00:15:59.392  24699-24722/com.androidgames.systemtests D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
10-03 00:15:59.402  24699-24699/com.androidgames.systemtests D/Atlas﹕ Validating map...
10-03 00:15:59.444  24699-24722/com.androidgames.systemtests I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build:  ()
    OpenGL ES Shader Compiler Version: E031.25.03.04
    Build Date: 04/06/15 Mon
    Local Branch:
    Remote Branch:
    Local Patches:
    Reconstruct Branch:
10-03 00:15:59.446  24699-24722/com.androidgames.systemtests I/OpenGLRenderer﹕ Initialized EGL, version 1.4
10-03 00:15:59.508  24699-24722/com.androidgames.systemtests D/OpenGLRenderer﹕ Enabling debug mode 0
10-03 00:16:09.783  24699-24699/com.androidgames.systemtests D/AndroidRuntime﹕ Shutting down VM
10-03 00:16:09.801  24699-24699/com.androidgames.systemtests E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.androidgames.systemtests, PID: 24699
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.androidgames.systemtests/com.androidgames.systemtests.AssetsTest}; have you declared this activity in your AndroidManifest.xml?
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1868)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1568)
            at android.app.Activity.startActivityForResult(Activity.java:3755)
            at android.app.Activity.startActivityForResult(Activity.java:3716)
            at android.app.Activity.startActivity(Activity.java:4036)
            at android.app.Activity.startActivity(Activity.java:3998)
            at com.androidgames.systemtests.AndroidBasicsStarter.onListItemClick(AndroidBasicsStarter.java:32)
            at android.app.ListActivity.onItemClick(ListActivity.java:319)
            at android.widget.AdapterView.performItemClick(AdapterView.java:305)
            at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
            at android.widget.AbsListView$PerformClick.run(AbsListView.java:3053)
            at android.widget.AbsListView.run(AbsListView.java:3860)
            at android.os.Handler.handleCallback(Handler.java:746)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5343)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

将此 <activity android:name=".AssetsTest"></activity> 插入您的 AndroidManifest.xml

参考访问 have you declared this activity in your AndroidManifest.xml