0

我在使用 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 调试环境中,我收到消息“jar 文件 c:\google android sdk\platforms\android-14\android.jar 没有源附件”。

我在哪里错了?

在此先感谢您的帮助

编辑:

我的日志猫错误消息:

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
4

2 回答 2

0

尝试这个

  1. Window -> Android SDK Manager -> 在 Android 4.0 下安装“Sources for Android SDK”

  2. 当提示“没有附加源...”时,单击按钮,然后选择目录“您的 Android SDK 目录/源/android-API 级别/”

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

于 2013-11-12T14:02:00.333 回答
0

您的代码中的导入部分似乎有问题。因为日志说它找不到您活动的通行证目录。这是系统试图找到的通行证,com.handpoint.headstart.sample.PrinterDriver但您在清单中定义的com.handpoint.headstart.android.PrinterDriver与另一个不同

于 2021-12-30T06:45:20.227 回答