アセットファイルへのパスが間違っているように感じますが、使用する正しいパスがわかりません。テキストファイルが実際にどこにあるかを再確認しましたが、assets
そのようなファイルまたはディレクトリがないというエラーが原因で、間違ったファイルまたはディレクトリが原因であると思われるのはなぜですか?
さまざまなフィールドを格納するために使用される質問コードの周りにラップされた条件付きコードがあります。このコードは、配列に4つに等しい要素があるかどうかを指定し、ファイルからのデータを配列リストに入力します。この条件が満たされない場合、ログにはエラーが表示されます。ファイルの名前は
- quiz1.txt
- quiz2.txt
- quiz3.txt
これがLogCatです
06-11 11:29:02.526: I/global(317): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
06-11 11:29:02.526: E/path of text file(317): What is the output of:
06-11 11:29:02.526: E/path of text file(317): echo 6 % 4;<.>
06-11 11:29:02.526: E/path of text file(317): 2<.>
06-11 11:29:02.526: E/path of text file(317): 4<.>
06-11 11:29:02.526: E/path of text file(317): 2<.>
06-11 11:29:02.526: E/path of text file(317): 0<.>
06-11 11:29:02.526: W/System.err(317): Error: read() /What is the output of:
06-11 11:29:02.526: W/System.err(317): echo 6 % 4;<.>
06-11 11:29:02.526: W/System.err(317): 2<.>
06-11 11:29:02.526: W/System.err(317): 4<.>
06-11 11:29:02.526: W/System.err(317): 2<.>
06-11 11:29:02.536: W/System.err(317): 0<.>
06-11 11:29:02.536: W/System.err(317): (No such file or directory)
06-11 11:29:02.536: E/YourApp(317): 1
06-11 11:29:02.536: E/YourApp(317): Data was not split from file correctly
06-11 11:29:02.536: I/global(317): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
06-11 11:29:02.536: E/path of text file(317): Which of following is NOT a valid comment in PHP<.>
06-11 11:29:02.536: E/path of text file(317): 3<.>
06-11 11:29:02.536: E/path of text file(317): // comment<.>
06-11 11:29:02.536: E/path of text file(317): # comment<.>
06-11 11:29:02.536: E/path of text file(317): <!-- comment --><.>
06-11 11:29:02.536: W/System.err(317): Error: read() /Which of following is NOT a valid comment in PHP<.>
06-11 11:29:02.536: W/System.err(317): 3<.>
06-11 11:29:02.536: W/System.err(317): / comment<.>
06-11 11:29:02.536: W/System.err(317): # comment<.>
06-11 11:29:02.536: W/System.err(317): <!-- comment --><.>
06-11 11:29:02.536: W/System.err(317): (No such file or directory)
06-11 11:29:02.536: E/YourApp(317): 1
06-11 11:29:02.536: E/YourApp(317): Data was not split from file correctly
06-11 11:29:02.546: I/global(317): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
06-11 11:29:02.546: E/path of text file(317): Which of following is a valid function definition in PHP<.>
06-11 11:29:02.546: E/path of text file(317): 3<.>
06-11 11:29:02.546: E/path of text file(317): int f()<.>
06-11 11:29:02.546: E/path of text file(317): private int f()<.>
06-11 11:29:02.546: E/path of text file(317): function f()<.>
06-11 11:29:02.546: W/System.err(317): Error: read() /Which of following is a valid function definition in PHP<.>
06-11 11:29:02.546: W/System.err(317): 3<.>
06-11 11:29:02.546: W/System.err(317): int f()<.>
06-11 11:29:02.546: W/System.err(317): private int f()<.>
06-11 11:29:02.546: W/System.err(317): function f()<.>
06-11 11:29:02.546: W/System.err(317): (No such file or directory)
06-11 11:29:02.546: E/YourApp(317): 1
06-11 11:29:02.546: E/YourApp(317): Data was not split from file correctly
以下はソースコードです
class Question
{
String question;
int answer;
String choice1;
String choice2;
String choice3;
}
public class Uploader extends Activity
{
private static final String LOGS = null;
Question q;
String textfile;
InputStream is;
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.basic);
ArrayList<Question> list = new ArrayList<Question>();
for (int i = 1; i <= 3; i++)
{
try {
AssetManager assetManager = getAssets();
// is = getResources().getAssets().open("quiz"+i+".txt");
//
String quizes[] = assetManager.list("myquizfolder");
for(String quiz : quizes) {
InputStream in = assetManager.open("myquizfolder/" + quiz);
textfile = convertStreamToString(in);
}
catch (IOException e)
{
// TODO Auto-generated catch block
Log.e("path of text file", textfile);
e.printStackTrace();
}
ResultsReader reader = new ResultsReader(textfile);
reader.read();
String str = ((ResultsReader) reader).getInput();
String data[] = str.split("<.>");
String datainfo = Integer.toString(data.length);
Log.e("YourApp", datainfo);
Question q = new Question();
if (data.length == 4)
{
q.question = data[0];
q.answer = Integer.parseInt(data[1]);
q.choice1 = data[2];
q.choice2 = data[3];
q.choice3 = data[4];
} else
{
Log.e("YourApp", "Data was not split from file correctly");
}
list.add(q);
}
}
}
public static String convertStreamToString(InputStream is)
throws IOException {
Writer writer = new StringWriter();
char[] buffer = new char[2048];
try {
Reader reader = new BufferedReader(new InputStreamReader(is,
"UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} finally {
is.close();
}
String text = writer.toString();
return text;
}