마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

갤럭시 s 시리즈 경로 오류 발생

0 추천

 

String root = Environment.getExternalStorageDirectory().toString();

file = new File( root + "/Sample/Input" );

list = file.listFiles();

이런식으로 이미지 불러오는데 다른 폰은 다 되는데 갤럭시 S 시리즈만 안되네요..(S노트 등등)

갤럭시 넥서스에서는 되는데 말이죠..

 

getAbsolutePath나 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) 을 통해서 DCIM에 Sample 폴더를 넣는 방식 등 다양하게 시도해봤지만.. 이유를 알 수 없이 경로 반환을 하지 못하는 것 같습니다.

다른 폰에서는 다 되는데 왜 갤럭시에서만 안되는지...

코드는 다음과 같습니다.

 

public class MainActivity extends Activity {

    private File file;
    File list[];
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        String root = Environment.getExternalStorageDirectory().toString();
 
        file = new File( root + "/Sample/Input" );
        list = file.listFiles();
 
        Toast.makeText(getBaseContext(), "" + list.length, Toast.LENGTH_SHORT).show();
   }
}
 
 
로그캣 메세지는 아래와 같습니다.
 
05-20 22:22:26.016  16677-16677/com.example.hyub.imc D/ResourcesManager﹕ creating new AssetManager and set to /data/app/com.example.hyub.imc-2/base.apk
05-20 22:22:26.076  16677-16677/com.example.hyub.imc V/BitmapFactory﹕ DecodeImagePath(decodeResourceStream3) : res/drawable/android_author.png
05-20 22:22:26.076  16677-16677/com.example.hyub.imc V/BitmapFactory﹕ DecodeImagePath(decodeResourceStream3) : res/drawable/ggg.png
05-20 22:22:26.106  16677-16677/com.example.hyub.imc V/BitmapFactory﹕ DecodeImagePath(decodeResourceStream3) : res/drawable/android_version.png
05-20 22:22:26.106  16677-16677/com.example.hyub.imc E/File﹕ fail readDirectory() errno=13
05-20 22:22:26.116  16677-16677/com.example.hyub.imc D/AndroidRuntime﹕ Shutting down VM
05-20 22:22:26.116  16677-16677/com.example.hyub.imc E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.hyub.imc, PID: 16677
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hyub.imc/com.example.hyub.imc.MainActivity}: java.lang.NullPointerException: Attempt to get length of null array
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5832)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
     Caused by: java.lang.NullPointerException: Attempt to get length of null array
            at com.example.hyub.imc.MainActivity.onCreate(MainActivity.java:93)
            at android.app.Activity.performCreate(Activity.java:6221)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5832)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
05-20 22:22:29.696  16677-16677/com.example.hyub.imc I/Process﹕ Sending signal. PID: 16677 SIG: 9
 
 
 

 

마트상 (290 포인트) 님이 2015년 5월 20일 질문
ㅠㅠ..도와주십시오..간절합니다.

2개의 답변

0 추천
테스트하고 있는 단말에 외부 저장소가 존재하지 않는것 아닌가요?

getExternalStorageState() 메소드로 상태가 어떤값으로 넘어오는지 체크해보세여
Gradler (109,780 포인트) 님이 2015년 5월 21일 답변
0 추천
익명사용자 님이 2015년 5월 21일 답변
...