안녕하세요^^ 여전히 후덥찌근한 날씨네요

 

다름이 아니라 sdcard에 파일을 생성후 쓰려고 하는데요..

 

우선 제가 짠 코드는 이렇습니다.

 

  public void onClick(View v){
  Log.d(null, "=====================Contact gogosing==================");
  String tmp = "dddddd";
  
  if(v.getId() == R.id.phonebook_button1){
   Log.d(null, "=====================WriteSdcard==================");
   try {
    common.writeSDCard(GetContact.this, tmp);
    Log.d(null, "===================Write Finish==================");
   } catch (Exception e) {
    common.showToast(this, "아놔 왜자꾸안되니");
   }
  }
 }

먼저 버튼을 누르면 파일을 생성하여 쓰려고 합니다.

 

  public void writeSDCard(Context context, String msg) throws IOException{
  Log.d(null, "==========================writeSDCard==========================");
  
  String sdCardPath = "";
  String ext = Environment.getExternalStorageState();
  
  Log.d(null, "==========================get path==========================");
  if(ext.equals(Environment.MEDIA_MOUNTED)){
   sdCardPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
  }else{
   sdCardPath = Environment.MEDIA_UNMOUNTED + "/";
  }
  
  Log.d(null, "==========================start write==========================");
  File file = new File(sdCardPath);
  if(!file.exists()) sdCardPath="";
  
  // File Create
  BufferedWriter out = new BufferedWriter(new FileWriter(sdCardPath + "test.txt"));
  out.write("test message");
  out.newLine();
  out.close();


클릭을 누르면 writeSDCard가 실행되어야(Common클래스에 선언해놓았습니다.) 하는데요..

 

이걸 실행해보고 로그캣을 보니까..

=====================Contact gogosing=================

=====================WriteSdcard==================

까지만 나옵니다..

이뒤에 널포인트exception 인듯한 말들이 나오구요..

 

 

핸드폰에선 예기치못한에러 뜨면서 종료되구요..

왜이러는걸까요?ㅠ.ㅠ

 

profile