这是链接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