我在这个安卓培训页面的代码中遇到了一个问题:https://developer.android.com/training/basics/network-ops/xml.html我下载了network usage.zip文件,并且没有修改任何代码。不幸的是,它既不能在我的手机上工作,也不能在我的模拟器上工作。
之后,我在谷歌上搜索了这个问题,并在这里找到了这个线程:Android Networkusage app,Error Parsing XML我试图用这个线程提供的解决方案来解决这个问题,但不幸的是,它不起作用,仍然显示错误:"Error parsing XML“
我非常确定错误是在清单文件中,因为我查看了我手机的设置,应用程序没有任何权限使用Wifi或移动数据。
这是我的"Android清单文件“,其余代码与从参考指南下载的代码完全相同:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.networkusage"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".NetworkActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="SettingsActivity" android:name=".SettingsActivity">
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
发布于 2017-09-29 05:16:00
对于任何有同样问题的人来说:我找到了一种让这款应用正常工作的方法。实际上,它在没有接触清单文件的情况下工作。但是,在"NetworkActivity.java"-file中,您需要更改一行并直接粘贴URL (见下文)。
@Override
protected String doInBackground(String... urls) {
try {
return loadXmlFromNetwork("https://stackoverflow.com/feeds/tag?tagnames=android&sort=newest%22");
// *here instead of urls[0] you have to add the URL manually. I guess, it is not the most elegant solution, but it works ;)*
} catch (IOException e) {
return getResources().getString(R.string.connection_error);
} catch (XmlPullParserException e) {
return getResources().getString(R.string.xml_error);
}
}https://stackoverflow.com/questions/46472589
复制相似问题