【发布时间】:2014-06-26 05:34:15
【问题描述】:
我在这个类的一个片段中:
public class NetworksList extends Fragment{
在我的onCreate 函数中,我也有这段代码:
XmlPullParserFactory pullParserFactory;
try {
pullParserFactory = XmlPullParserFactory.newInstance();
XmlPullParser parser = pullParserFactory.newPullParser();
InputStream in_s = getActivity().getApplicationContext().getAssets().open("temp.xml");
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(in_s, null);
Toast.makeText(getActivity().getApplicationContext(), "size: ", Toast.LENGTH_LONG).show();
parseXML(parser);
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
希望我尝试用它来打开 XML 文件。我的资产文件夹中有我的 XML 文件,但我得到了:
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ java.io.FileNotFoundException: temp.xml
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ at android.content.res.AssetManager.openAsset(Native Method)
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ at android.content.res.AssetManager.open(AssetManager.java:316)
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ at android.content.res.AssetManager.open(AssetManager.java:290)
05-08 18:03:11.034 24645-24645/pt.smartgeo.aees W/System.err﹕ at pt.smartgeo.aees.NetworksList$2.onClick(NetworksList.java:77)
FileNotFound... 我如何知道将 temp.xml 文件放在何处以便在 NetworksList 类中打开它?
【问题讨论】:
-
看起来应该可以了。您可以将您的 xml 放在
raw文件夹中并通过它的 id 访问它:context.getResources().openRawResource(R.raw.temp); -
原始文件夹在哪里?
-
可以在
res文件夹下创建。
标签: android xml android-assets