这里是链接http://developer.android.com/training/basics/network-ops/xml.html,示例代码在右侧下载。
我正在使用wi-fi连接,有些人建议禁用LAN卡,我这样做了,仍然例外......并且所有与read 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
答案 0 :(得分:0)
编辑: - 我下载并将示例导入Eclipse。为了让它运行我必须编辑Android清单,以便它读取
<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会一直抱怨我。如果您从文档中复制了该行,则值得将其删除。我不认为这是基于发布的例外的问题但是......