tags:

views:

67

answers:

3

Hi,

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.674: 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.

+1  A: 

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

Vinayak.B
Thanks for your reply.So from your point of view it is not possible to refer the files in the system's D: from the emulator.
Rajapandian
Yea obviously or else it may be of no sense to refer directly to the system folder..
Vinayak.B
I think if i explain my whole application, then you can easily understand my problem.What i want to achieve is , to develop a small bluetooth application.I connected a Boluetooth dongle to my system and i having one bluetooth enabled device, and if i sent any vcard, the java program running in my system will read the vcard and store that in systems D:.and i have one android application running and listening that folder ,if any new file comes it will read that file and store that into the sdcard.
Rajapandian
A: 

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.

XC
A: 

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?

Jeremy Anderson