无法启动新的Android活动

时间:2013-11-12 13:45:25

标签: java android eclipse android-activity

我在使用Eclipse编写的代码启动新的Android活动时遇到了一些麻烦。我正在尝试从名为HomeActivity的主要活动中启动我的PrinterDriver活动。然而,它崩溃了,我不知道为什么。

HomeActivity中的代码是

public void PrintMessage(StringBuilder sb) {
    Intent intent = new Intent(this, PrinterDriver.class);
    String message = sb.toString();
    intent.putExtra("PrintableString", message);
    startActivity(intent);
}

PrinterDriver中的代码是

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.printing);
    Intent intent = getIntent();
    String sb = intent.getExtras().getString("PrintableString");
    new AlertDialog.Builder(PrinterDriver.this).setMessage(sb.toString()).show();

}

我的PrinterDriver活动的清单文件代码是

    <activity android:name="com.handpoint.headstart.android.PrinterDriver"
              android:theme="@android:style/Theme.Dialog"
              android:screenOrientation="portrait"
              >
        <intent-filter>
            <action android:name="com.handpoint.headstart.android.PrinterDriver" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

代码似乎永远不会像PrinterDriver中的onCreate方法那样。我在startActivity函数中放置了一个断点,它已经到了那里但没有更进一步。在Eclipse Debug环境中,我收到消息“jar文件c:\ google android sdk \ platforms \ android-14 \ android.jar没有源代码附件”。

我在哪里错了?

提前感谢您的帮助

编辑:

我的日志cat错误消息:

11-12 14:25:13.933: E/QcrilMsgTunnelSocket(10629): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
11-12 14:25:15.875: E/MP-Decision(1702): num online cores: 1 reqd : 2 available : 4 rq_depth:1.000000 hotplug_avg_load_dw: 68
11-12 14:25:15.875: E/MP-Decision(1702): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:0.000000
11-12 14:25:16.476: E/MP-Decision(1702): num online cores: 2 reqd : 1 available : 4 rq_depth:0.000000 hotplug_avg_load_dw: 29
11-12 14:25:16.476: E/MP-Decision(1702): DOWN cpu:1 core_idx:1 Ns:1.100000 Ts:190 total_time_down:196.000000
11-12 14:25:17.287: E/MP-Decision(1702): num online cores: 1 reqd : 2 available : 4 rq_depth:1.000000 hotplug_avg_load_dw: 62
11-12 14:25:17.287: E/MP-Decision(1702): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:0.000000
11-12 14:25:17.727: E/MP-Decision(1702): num online cores: 2 reqd : 1 available : 4 rq_depth:0.000000 hotplug_avg_load_dw: 11
11-12 14:25:17.727: E/MP-Decision(1702): DOWN cpu:1 core_idx:1 Ns:1.100000 Ts:190 total_time_down:196.000000
11-12 14:25:17.937: E/QcrilMsgTunnelSocket(10629): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
11-12 14:25:19.048: E/AndroidRuntime(11031): FATAL EXCEPTION: main
11-12 14:25:19.048: E/AndroidRuntime(11031): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.handpoint.headstart.sample/com.handpoint.headstart.sample.PrinterDriver}; have you declared this activity in your AndroidManifest.xml?
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1635)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.app.Activity.startActivityForResult(Activity.java:3430)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.app.Activity.startActivityForResult(Activity.java:3391)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.app.Activity.startActivity(Activity.java:3626)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.app.Activity.startActivity(Activity.java:3594)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at com.handpoint.headstart.sample.ui.HomeActivity.PrintMessage(HomeActivity.java:1100)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at com.handpoint.headstart.sample.ui.HomeActivity$10$1.onClick(HomeActivity.java:1082)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:976)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.widget.AdapterView.performItemClick(AdapterView.java:301)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.widget.AbsListView.performItemClick(AbsListView.java:1519)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3291)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.widget.AbsListView$1.run(AbsListView.java:4340)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.os.Handler.handleCallback(Handler.java:725)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.os.Looper.loop(Looper.java:137)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at android.app.ActivityThread.main(ActivityThread.java:5328)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at java.lang.reflect.Method.invokeNative(Native Method)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at java.lang.reflect.Method.invoke(Method.java:511)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
11-12 14:25:19.048: E/AndroidRuntime(11031):    at dalvik.system.NativeStart.main(Native Method)
11-12 14:25:19.389: E/MP-Decision(1702): num online cores: 1 reqd : 2 available : 4 rq_depth:1.000000 hotplug_avg_load_dw: 53
11-12 14:25:19.389: E/MP-Decision(1702): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:0.000000
11-12 14:25:19.409: E/android.os.Debug(780): !@Dumpstate > sdumpstate -k -t -z -d -o /data/log/dumpstate_app_error
11-12 14:25:19.789: E/MP-Decision(1702): num online cores: 2 reqd : 1 available : 4 rq_depth:1.000000 hotplug_avg_load_dw: 11
11-12 14:25:19.789: E/MP-Decision(1702): DOWN cpu:1 core_idx:1 Ns:1.100000 Ts:190 total_time_down:49.000000
11-12 14:25:20.710: E/MP-Decision(1702): num online cores: 1 reqd : 2 available : 4 rq_depth:2.500000 hotplug_avg_load_dw: 49
11-12 14:25:20.710: E/MP-Decision(1702): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:147.000000
11-12 14:25:20.910: E/MP-Decision(1702): num online cores: 2 reqd : 3 available : 4 rq_depth:2.700000 hotplug_avg_load_dw: 79
11-12 14:25:20.910: E/MP-Decision(1702): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:0.000000
11-12 14:25:20.910: E/MP-Decision(1702): UP cpu:2 core_idx:2 Nw:2.700000 Tw:90 total_time_up:137.000000
11-12 14:25:21.161: E/MP-Decision(1702): num online cores: 3 reqd : 2 available : 4 rq_depth:1.300000 hotplug_avg_load_dw: 66
11-12 14:25:21.161: E/MP-Decision(1702): DOWN cpu:2 core_idx:2 Ns:2.100000 Ts:240 total_time_down:242.000000
11-12 14:25:21.761: E/QSEECOMAPI:(11198): Error::Failed to open /dev/qseecom device
11-12 14:25:21.761: E/QSEECOMAPI:(11198): Error::Failed to open /dev/qseecom device
11-12 14:25:21.761: E/QSEECOMAPI:(11198): Error::Failed to open /dev/qseecom device
11-12 14:25:21.761: E/QSEECOMAPI:(11198): Error::Failed to open /dev/qseecom device
11-12 14:25:21.761: E/QSEECOMAPI:(11198): Error::Failed to open /dev/qseecom device
11-12 14:25:21.931: E/QcrilMsgTunnelSocket(10629): IOExceptionjava.io.IOException: No such file or directoryReason: No such file or directory
11-12 14:25:22.562: E/MP-Decision(1702): num online cores: 2 reqd : 3 available : 4 rq_depth:3.300000 hotplug_avg_load_dw: 101
11-12 14:25:22.562: E/MP-Decision(1702): UP cpu:1 core_idx:1 Nw:1.900000 Tw:140 total_time_up:0.000000
11-12 14:25:22.562: E/MP-Decision(1702): UP cpu:2 core_idx:2 Nw:2.700000 Tw:90 total_time_up:98.000000

1 个答案:

答案 0 :(得分:0)

试试这个

  1. 窗口 - &gt; Android SDK Manager - &gt;在Android 4.0下安装“Android SDK源代码”

  2. 当“未附加资源...”提示时,请点击该按钮,然后选择目录“您的Android SDK目录/ sources / android-API级别/”

  3. 示例:C:... \ android-sdk-windows \ sources \ android-16