在我的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)
答案 0 :(得分:1)
您可以在startActivity()
中排除包名称。你试过了吗?
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, MyListView.class));
}
你的清单看起来还不错!