我有一个列表视图,当我点击一个项目时它会显示一条消息然后当我点击“确定”时我想传递给另一个活动,这是我的代码:
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
ServerContent item = listAdapter.getItem(position);
Log.e("onitemclick","listadapter");
item.select();
newactivity n = new newactivity();
Intent newActivity = new Intent();
startActivity(newActivity);
}
我将其添加到manifest.xml
中<activity android:label="@string/app_name" android:name="newactivity"/>
这是新活动:
public class newactivity {
Intent intent;
protected void onCreate(Bundle savedInstanceState) {
intent = getIntent();
intent.addCategory("category");
//String value = intent.getStringExtra("key"); //if it's a string you stored.
}
private Intent getIntent() {
// TODO Auto-generated method stub
Intent n = new Intent();
n.addCategory(" ");
return n;
}
我收到了这些错误
10-18 11:01:02.277: W/dalvikvm(333): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-18 11:01:02.297: E/AndroidRuntime(333): FATAL EXCEPTION: main
10-18 11:01:02.297: E/AndroidRuntime(333): android.content.ActivityNotFoundException: No Activity found to handle Intent { }
10-18 11:01:02.297: E/AndroidRuntime(333): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.app.Activity.startActivityFromChild(Activity.java:3067)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.app.Activity.startActivityForResult(Activity.java:2847)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.app.Activity.startActivity(Activity.java:2933)
10-18 11:01:02.297: E/AndroidRuntime(333): at com.upnpexample.BrowseServerActivity$1$1.onItemClick(BrowseServerActivity.java:227)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.widget.ListView.performItemClick(ListView.java:3513)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.os.Handler.handleCallback(Handler.java:587)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.os.Handler.dispatchMessage(Handler.java:92)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.os.Looper.loop(Looper.java:123)
10-18 11:01:02.297: E/AndroidRuntime(333): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-18 11:01:02.297: E/AndroidRuntime(333): at java.lang.reflect.Method.invokeNative(Native Method)
10-18 11:01:02.297: E/AndroidRuntime(333): at java.lang.reflect.Method.invoke(Method.java:507)
10-18 11:01:02.297: E/AndroidRuntime(333): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-18 11:01:02.297: E/AndroidRuntime(333): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-18 11:01:02.297: E/AndroidRuntime(333): at dalvik.system.NativeStart.main(Native Method)
10-18 11:01:05.376: I/Process(333): Sending signal. PID: 333 SIG: 9
答案 0 :(得分:1)
活动名称必须与此.newactivity
就像这样改变
<activity android:label="@string/app_name" android:name=".newactivity"/>
答案 1 :(得分:0)
我希望它不是一个错字:
<activity android:label="@string/app_name" android:name="newactivity"/>
没有“。”这里是活动名称之前的。 应该是这样的:
<activity android:label="@string/app_name" android:name=".newactivity"/>
或者您甚至可以指定活动的完整限定名称,例如
<activity android:label="@string/app_name" android:name="com.yourproject.activity.newactivity"/>