所以我正在使用Android应用程序,我正在使用来自数据库的元素填充ListActivity,然后使用onListItemClick移动到基于用户选择的行传递信息的新活动。唯一的问题似乎是我如何做意图,导致应用程序崩溃。
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Movie m = (Movie) this.getListAdapter().getItem(position);
long selection = m.getId();
//Toast.makeText(this, "You have chosen the movie: " + " " + selection, Toast.LENGTH_LONG).show();
Intent viewTrailer = new Intent(MainActivity.this, ViewTrailer.class);
viewTrailer.putExtra("movieId", selection);
startActivity(viewTrailer);
}
Toast只是用于调试目的。 应该发生的是,意图根据他们的选择获得额外的Id并将其传递给下一个活动。选择得到正确的值,但程序在
崩溃 startActivity(viewTrailer)
行,我收到一条错误说明:源附件不包含文件instrumentation.class的源。我怀疑这个问题是我的来源,看看我是如何使用其他只是编码错误的文件来获取这些文件的。
此外,我已更新我的清单以包含新活动。这是日志猫
12-05 22:02:08.462: W/ActivityThread(2583): Application com.example.movies is waiting for the debugger on port 8100...
12-05 22:02:08.482: I/System.out(2583): Sending WAIT chunk
12-05 22:02:08.492: I/dalvikvm(2583): Debugger is active
12-05 22:02:08.693: I/System.out(2583): Debugger has connected
12-05 22:02:08.693: I/System.out(2583): waiting for debugger to settle...
12-05 22:02:08.902: I/System.out(2583): waiting for debugger to settle...
12-05 22:02:09.112: I/System.out(2583): waiting for debugger to settle...
12-05 22:02:09.323: I/System.out(2583): waiting for debugger to settle...
12-05 22:02:09.532: I/System.out(2583): waiting for debugger to settle...
12-05 22:02:09.738: I/System.out(2583): waiting for debugger to settle...
12-05 22:02:09.942: I/System.out(2583): waiting for debugger to settle...
12-05 22:02:10.153: I/System.out(2583): debugger has settled (1315)
12-05 22:02:10.562: D/dalvikvm(2583): GC_EXTERNAL_ALLOC freed 41K, 51% free 2667K/5379K, external 1541K/1559K, paused 128ms
12-05 22:02:11.152: D/gralloc_goldfish(2583): Emulator without GPU emulation detected.
12-05 22:02:14.639: W/dalvikvm(2583): JNI WARNING: JNI method called with exception raised
12-05 22:02:14.639: W/dalvikvm(2583): in Landroid/os/Process;.setArgV0 (Ljava/lang/String;)V (GetStringCritical)
12-05 22:02:14.639: W/dalvikvm(2583): Pending exception is:
12-05 22:02:14.639: I/dalvikvm(2583): Ljava/lang/reflect/InvocationTargetException;:
12-05 22:02:14.639: I/dalvikvm(2583): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 22:02:14.639: I/dalvikvm(2583): at java.lang.reflect.Method.invoke(Method.java:507)
12-05 22:02:14.639: I/dalvikvm(2583): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-05 22:02:14.639: I/dalvikvm(2583): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-05 22:02:14.639: I/dalvikvm(2583): at dalvik.system.NativeStart.main(Native Method)
12-05 22:02:14.639: I/dalvikvm(2583): Caused by:
12-05 22:02:14.639: I/dalvikvm(2583): Landroid/content/ActivityNotFoundException;: Unable to find explicit activity class {com.example.movies/com.example.movies.ViewTrailer}; have you declared this activity in your AndroidManifest.xml?
12-05 22:02:14.639: I/dalvikvm(2583): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
12-05 22:02:14.639: I/dalvikvm(2583): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
12-05 22:02:14.639: I/dalvikvm(2583): at android.app.Activity.startActivityForResult(Activity.java:2827)
12-05 22:02:14.639: I/dalvikvm(2583): at android.app.Activity.startActivity(Activity.java:2933)
12-05 22:02:14.639: I/dalvikvm(2583): at com.example.movies.MainActivity.onListItemClick(MainActivity.java:52)
12-05 22:02:14.639: I/dalvikvm(2583): at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
12-05 22:02:14.639: I/dalvikvm(2583): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
12-05 22:02:14.639: I/dalvikvm(2583): at android.widget.ListView.performItemClick(ListView.java:3513)
12-05 22:02:14.639: I/dalvikvm(2583): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
12-05 22:02:14.639: I/dalvikvm(2583): at android.os.Handler.handleCallback(Handler.java:587)
12-05 22:02:14.639: I/dalvikvm(2583): at android.os.Handler.dispatchMessage(Handler.java:92)
12-05 22:02:14.639: I/dalvikvm(2583): at android.os.Looper.loop(Looper.java:130)
12-05 22:02:14.639: I/dalvikvm(2583): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-05 22:02:14.639: I/dalvikvm(2583): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 22:02:14.639: I/dalvikvm(2583): at java.lang.reflect.Method.invoke(Method.java:507)
12-05 22:02:14.642: I/dalvikvm(2583): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-05 22:02:14.642: I/dalvikvm(2583): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-05 22:02:14.642: I/dalvikvm(2583): at dalvik.system.NativeStart.main(Native Method)
12-05 22:02:14.642: I/dalvikvm(2583): "main" prio=5 tid=1 NATIVE
12-05 22:02:14.642: I/dalvikvm(2583): | group="main" sCount=0 dsCount=0 obj=0xb60f4c38 self=0x8530e48
12-05 22:02:14.642: I/dalvikvm(2583): | sysTid=2583 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=-2145907712
12-05 22:02:14.642: I/dalvikvm(2583): at android.os.Process.setArgV0(Native Method)
12-05 22:02:14.642: I/dalvikvm(2583): at android.app.ActivityThread.main(ActivityThread.java:3668)
12-05 22:02:14.642: I/dalvikvm(2583): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 22:02:14.642: I/dalvikvm(2583): at java.lang.reflect.Method.invoke(Method.java:507)
12-05 22:02:14.642: I/dalvikvm(2583): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-05 22:02:14.642: I/dalvikvm(2583): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-05 22:02:14.642: I/dalvikvm(2583): at dalvik.system.NativeStart.main(Native Method)
12-05 22:02:14.642: E/dalvikvm(2583): VM aborting
到目前为止,viewTrailer并没有太多东西(试图在我做任何事之前让它运行)
public class ViewTrailer extends Activity
{
private TextView movieNumber;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_trailer);
// movieNumber = (TextView) findViewById(R.id.movieNumber);
//
// long movieId;
//
// Bundle nameBundle = new Bundle();
// nameBundle = getIntent().getExtras();
// movieId = nameBundle.getLong("movieId");
//
// movieNumber.setText(String.valueOf(movieId));
}
}
无论是否有评论都尝试过,但两者都会崩溃。