Java 使用微调器从资产文件夹访问文件
我在asset目录中存储了一些文本文件,希望在我的程序中读取它们。 我创建了一个微调器来列出可用的文本文件。选择已读取文件的文件 我使用的xml代码是:Java 使用微调器从资产文件夹访问文件,java,android,xml,android-spinner,Java,Android,Xml,Android Spinner,我在asset目录中存储了一些文本文件,希望在我的程序中读取它们。 我创建了一个微调器来列出可用的文本文件。选择已读取文件的文件 我使用的xml代码是: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:lay
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff000000"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:baselineAligned="true"
android:gravity="bottom" >
<TableRow
android:layout_width="wrap_content"
android:padding="10dp" >
<Spinner
android:id="@+id/spinner1"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/wm_arrays"
android:prompt="@string/watermark_size"
/>
</TableRow>
<TableRow android:padding="5dp" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="insert"
android:text="Apply" />
</TableRow>
<TableRow android:padding="5dp" >
<TextView
android:id="@+id/displaystring"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="String: "
android:textColor="#ffffff" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
}
我得到一个空指针异常,其中实际上意味着输入未被读取。
谁能帮帮我试试这个吗
=
始终只比较两个引用
String您应该使用.equals(“”
对剩余的所有条件都这样做。也可以使用if-else if
if(res.equals("1B")){
input = assetManager.open("wmark_8.txt");
}else if(res.equals("2B")){
input = assetManager.open("wmark_16.txt");
}
if(res.equals("1B")){
input = assetManager.open("wmark_8.txt");
}else if(res.equals("2B")){
input = assetManager.open("wmark_16.txt");
}