简体   繁体   English

无法启动新的 Android 活动

[英]Trouble launching new Android activity

I'm having some trouble with launching a new Android activity with code written in Eclipse.我在使用 Eclipse 编写的代码启动新的 Android 活动时遇到了一些麻烦。 I am trying to launch my PrinterDriver activity from my main activity named HomeActivity.我正在尝试从名为 HomeActivity 的主要活动启动我的 PrinterDriver 活动。 However, it crashes and I'm not sure why.但是,它崩溃了,我不确定为什么。

The code in HomeActivity is HomeActivity 中的代码是

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

The code in PrinterDriver is打印机驱动程序中的代码是

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();

} }

My manifest file code for PrinterDriver activity is我的 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>

The code never seems to get as far as the onCreate method in PrinterDriver.代码似乎永远无法达到 PrinterDriver 中的 onCreate 方法。 I've placed a breakpoint at the startActivity function and it's getting to there OK but no further.我在 startActivity 函数上放置了一个断点,它可以到达那里,但不能再进一步了。 In the Eclipse Debug environment I get the message, "the jar file c:\\google android sdk\\platforms\\android-14\\android.jar has no source attachment".在 Eclipse 调试环境中,我收到消息“jar 文件 c:\\google android sdk\\platforms\\android-14\\android.jar 没有源附件”。

Where am I going wrong here?我哪里出错了?

Thanks in advance for your help在此先感谢您的帮助

Edit:编辑:

My log cat error messages:我的日志猫错误消息:

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

Try this 尝试这个

  1. Window -> Android SDK Manager -> install "Sources for Android SDK" under Android 4.0 窗口-> Android SDK管理器->在Android 4.0下安装“ Android SDK的源”

  2. When prompted by "No sources attached...", click the button, then choose the Directory "your Android SDK directory/sources/android-API level/" 当出现“未附加任何来源...”提示时,单击按钮,然后选择目录“您的Android SDK目录/源/ android-API级别/”

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

It seems you have problem with the import section in your code.您的代码中的导入部分似乎有问题。 Because the log says that it couldn't find the pass directory of your activity.因为日志说找不到你活动的pass目录。 This is the pass that system is trying to find com.handpoint.headstart.sample.PrinterDriver but what you defined in your manifest is com.handpoint.headstart.android.PrinterDriver which is different from the another one这是系统试图找到com.handpoint.headstart.sample.PrinterDriver但您在清单中定义的是com.handpoint.headstart.android.PrinterDriver ,它与另一个不同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM