1

在我的 android 应用程序中,有一个名为 mylistview 的 xml 文件:

<?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:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/app_name" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

并且有一个 MyListView JAva 源:

package ir.smspeik.sms;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MyListView extends ListActivity {
    /** Called when the activity is first created. */
    TextView selection;
    String[] names;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mylistview);
        names = new String[] { "sunday", "monday", "tuesday", "wednesday",      
                "thrusday", "friday", "saturday",};      
        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.listlayout, R.id.label,names));     
        selection=(TextView)findViewById(R.id.label);
    }

    public void onListItemClick(ListView parent, View v, int position, long id) {
        selection.setText(names[position]);
    }
}

我开始:

ImageButton btnRealState = (ImageButton) findViewById(R.id.imgbtnRealstate);
        btnRealState.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this,
                        ir.smspeik.sms.MyListView.class));
            }
        });

在 AndroidManifest.xml 中:

 <activity
            android:name=".MyListView" android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="ir.smspeik.sms.MyListView" />

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

但是当我想启动它时,这个错误就会缓解:

09-14 20:25:56.780: E/AndroidRuntime(760): FATAL EXCEPTION: main
09-14 20:25:56.780: E/AndroidRuntime(760): android.content.ActivityNotFoundException: Unable to find explicit activity class {ir.smspeik.sms/ir.smspeik.sms.MyListView}; have you declared this activity in your AndroidManifest.xml?
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.app.Activity.startActivityForResult(Activity.java:3351)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.app.Activity.startActivityForResult(Activity.java:3312)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.app.Activity.startActivity(Activity.java:3522)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.app.Activity.startActivity(Activity.java:3490)
09-14 20:25:56.780: E/AndroidRuntime(760):  at ir.smspeik.sms.MainActivity$3.onClick(MainActivity.java:62)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.view.View.performClick(View.java:4084)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.view.View$PerformClick.run(View.java:16966)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.os.Handler.handleCallback(Handler.java:615)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.os.Looper.loop(Looper.java:137)
09-14 20:25:56.780: E/AndroidRuntime(760):  at android.app.ActivityThread.main(ActivityThread.java:4745)
09-14 20:25:56.780: E/AndroidRuntime(760):  at java.lang.reflect.Method.invokeNative(Native Method)
09-14 20:25:56.780: E/AndroidRuntime(760):  at java.lang.reflect.Method.invoke(Method.java:511)
09-14 20:25:56.780: E/AndroidRuntime(760):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-14 20:25:56.780: E/AndroidRuntime(760):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-14 20:25:56.780: E/AndroidRuntime(760):  at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

1

您可以将包名称排除在startActivity(). 你试过吗?

public void onClick(View v) {
     startActivity(new Intent(MainActivity.this, MyListView.class));
}

您的清单看起来不错!

于 2012-09-14T20:54:32.527 回答