无法解析getAssets()方法 [英] cannot resolve getAssets() method
本文介绍了无法解析getAssets()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用getAsset()方法时遇到了麻烦.我试图从资产文件夹中将XML文件与getAsset()一起放入inputStream中.
hi i have been having trouble with the getAsset() method. i trying to get a xml file from the assets folder with the getAsset() to be put into a inputStream.
代码:
public class MainActivity extends AppCompatActivity {
List people;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
InputStream is = getAssets().open("people.xml");
people = XMLParser.readPeople(is);
}catch (IOException e){
e.printStackTrace();
}
}
}
XML:
<people>
<person>
<name>joe</name>
<dob>11/08/16</dob>
<gender>male</gender>
</person>
</people>
谁能告诉我getAssets()方法的作用
can anyone tell me what going on with the getAssets() method
推荐答案
代替此
try {
InputStream is = getAssets().open("people.xml");
people = XMLParser.readPeople(is);
}catch (IOException e){
e.printStackTrace();
}
使用此
try {
AssetManager assetManager = getBaseContext().getAssets();
InputStream is = assetManager.open("people.xml");
people = XMLParser.readPeople(is);
}catch (IOException e){
e.printStackTrace();
}
这篇关于无法解析getAssets()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文