开发者

Problem in refering Files from Android emulator?

I have one problem , i want to refer particular file in my system D: from my android emulator,but it throwing Nullpointer Exception, Here is my code

for (File file : new File("D:\\vcards").listFiles())
        {
            i++;
        }
Log.i("I",""+i);

If i run this code in core java application it prints the no of files in the folder,but in android application it gives NUllpointer Exception

02-08 10:10:09.653: WARN/System.err(439): java.lang.NullPointerException
02-08 10:10:09.653: WARN/System.err(439):  at payoda.android.Temp.onCreate(Temp.java:22)
02-08 10:10:09.664: WARN/System.err(439):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-08 10:10:09.664: WARN/System.err(439):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
02-08 10:10:09.67开发者_如何学C4: WARN/System.err(439):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
02-08 10:10:09.674: WARN/System.err(439):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
02-08 10:10:09.674: WARN/System.err(439):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
02-08 10:10:09.684: WARN/System.err(439):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-08 10:10:09.684: WARN/System.err(439):  at android.os.Looper.loop(Looper.java:123)
02-08 10:10:09.694: WARN/System.err(439):  at android.app.ActivityThread.main(ActivityThread.java:4363)
02-08 10:10:09.694: WARN/System.err(439):  at java.lang.reflect.Method.invokeNative(Native Method)
02-08 10:10:09.694: WARN/System.err(439):  at java.lang.reflect.Method.invoke(Method.java:521)
02-08 10:10:09.704: WARN/System.err(439):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-08 10:10:09.704: WARN/System.err(439):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-08 10:10:09.713: WARN/System.err(439):  at dalvik.system.NativeStart.main(Native Method)

I dont know how to how to get the no of file files in that folder through Android program.If anybody knows the answer please help me.


It is required to push the files to either your emulator memory or the SDcard to refer to the files..


Your Android emulator doesn't have access to the local resources on your computer, only the emulated hardware and SD storage of the emulator itself. You wouldn't expect your phone to have direct access to your computer's hard drive would you?


1) How can you ensure you have drive D: and there is on folder named 'vcards'? Do you means the SD card?

2) What you import 'java.io.File'?

3) If you have question about the difference between core Java application and Android application, you might have a NullPointer exception handling by yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜