텍스트 파일 불러와서 ListView에 적용시키려고 합니다.
이 소스는 원래는 TextView에 적용시킨건데, 변형해서 ListView에 적용하려 하는데요
주석처리된 부분을 빨간부분처럼 바꾸어 보았습니다(main.xml 파일에 ListView 레이아웃 만들었구요)
strBuffer 부분을 ListView에 적용 시켜야 되는거 같은데;;;
어떻게 수정해야할지 모르겠어서요.
소스상에는 에러가 없다고 나오구요.
에뮬레이터로 실행시키면 예기치 않은 에러로 종료되는 상황입니다.
public class FileWR extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList <String> arGeneral = new ArrayList();
//파일 읽기
String strFileName = "Filename.txt";
StringBuffer strBuffer = new StringBuffer();
try {
FileInputStream fis = openFileInput(strFileName.toString());
DataInputStream dataIO = new DataInputStream(fis);
String strLine = null;
while( (strLine = dataIO.readLine()) != null)
strBuffer.append(strLine + "\n");
dataIO.close();
fis.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//어댑터 준비
ArrayAdapter<String> Adapter;
Adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,arGeneral);
//어댑터 연결
ListView carlist = (ListView) findViewById(R.id.ListView01);
carlist.setAdapter(Adapter);
/* TextView textView = new TextView(this);
textView.setText(strBuffer);
*/
}
}
Logcat을 보여주세요