1

这是链接http://developer.android.com/training/basics/network-ops/xml.html,示例代码在右侧供下载。

我正在使用 wi-fi 连接,一些人建议禁用 LAN 卡,我这样做了,仍然有例外......并且所有与读取 xml 相关的项目都无法在我的模拟器上运行。

它提示我这个错误

10-11 08:41:43.169: E/AndroidRuntime(825): FATAL EXCEPTION: main
10-11 08:41:43.169: E/AndroidRuntime(825): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.networkusage/com.example.networkusage.NetworkActivity}: java.lang.ClassNotFoundException: com.example.networkusage.NetworkActivity
10-11 08:41:43.169: E/AndroidRuntime(825):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
10-11 08:41:43.169: E/AndroidRuntime(825):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-11 08:41:43.169: E/AndroidRuntime(825):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-11 08:41:43.169: E/AndroidRuntime(825):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-11 08:41:43.169: E/AndroidRuntime(825):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 08:41:43.169: E/AndroidRuntime(825):  at android.os.Looper.loop(Looper.java:137)
10-11 08:41:43.169: E/AndroidRuntime(825):  at android.app.ActivityThread.main(ActivityThread.java:4745)
10-11 08:41:43.169: E/AndroidRuntime(825):  at java.lang.reflect.Method.invokeNative(Native Method)
10-11 08:41:43.169: E/AndroidRuntime(825):  at java.lang.reflect.Method.invoke(Method.java:511)
10-11 08:41:43.169: E/AndroidRuntime(825):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-11 08:41:43.169: E/AndroidRuntime(825):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-11 08:41:43.169: E/AndroidRuntime(825):  at dalvik.system.NativeStart.main(Native Method)
10-11 08:41:43.169: E/AndroidRuntime(825): Caused by: java.lang.ClassNotFoundException: com.example.networkusage.NetworkActivity
10-11 08:41:43.169: E/AndroidRuntime(825):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-11 08:41:43.169: E/AndroidRuntime(825):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-11 08:41:43.169: E/AndroidRuntime(825):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-11 08:41:43.169: E/AndroidRuntime(825):  at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
10-11 08:41:43.169: E/AndroidRuntime(825):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
10-11 08:41:43.169: E/AndroidRuntime(825):  ... 11 more
4

1 回答 1

0

编辑:- 我下载并将示例导入到 Eclipse。为了让它运行,我必须编辑 android manifest 让它读

<activity
            <!-- note removed all but simple name from android:name -->
            android:name="NetworkActivity" 
            android:label="@string/app_name" >
            <!-- more stuff -->
</activity>

看来您需要将 com.example.networkusage.NetworkActivity 添加到 AndroidManifest

        <activity 
            android:name="com.example.networkusage.NetworkActivity"
        </activity>

Google 的开发人员文档也存在一个问题,您的清单不应该有

<?xml version="1.0" encoding="utf-8"?>

在顶部。如果我包含它,至少 Eclipse 总是会为我抱怨。如果您从文档中复制了该行,则值得将其删除。我不认为这是基于发布的异常的问题,但是......

于 2012-10-11T09:01:18.950 回答