Androidスタジオでファイルを読み込み、各文字列をarraylistに配置しようとしていますが、arraylistから文字列を取得しようとするとアプリがクラッシュします(メッセージ:「残念なことに、App停止しました ")誰かが何が間違っているか教えていただけますか?arraylist.get()がAndroidスタジオで自分のアプリをクラッシュする
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
////////////////////////////////////////////////////////////////////////////
String text = "";
tv_view = (TextView) findViewById(R.id.textview1);
Scanner s = new Scanner(System.in);
File n = new File("C:\\Users\\Admin\\AndroidStudioProjects\\LOTOS.1\\app\\src\\main\\assets\\nouns.txt");
//Instantiate Scanner s with f variable within parameters
//surround with try and catch to see whether the file was read or not
try {
s = new Scanner(n);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//Instantiate a new ArrayList of String type
ArrayList<String> theWord = new ArrayList<String>();
//while it has next ..
while(s.hasNext()){
//Initialise str with word read
String str=s.next();
//add to ArrayList
theWord.add(str);
}
text = theWord.get(150);
tv_view.setText(text);
//return ArrayList
}
これはEclipseでうまく動作します –
@ShaishavJogani問題は、イベントログにエラーがなくコンパイルされていることです。しかし、アプリケーションがクラッシュする –
クラッシュした場合、間違いなく間違いがあります。 –