Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

csv file is not created

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create the CSV file using my android application.So i uses Opencsv library to create CSV file.Below is my code



i called this method in my android class.below is my code for that.but it doesn't create any files in C drive.where is the error.I ran the application emulatoor.not the real phone?

 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Files created in an emulator will not be stored on the host's file system. There is a virtual disk used by the emulator for the internal storage and possible a second one used for the sd card. You will need to use apps in the emulator to find the file or use adp to explore the phone's file system.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should also read the log cat output to see if there are any reputed errors. I suspect there will be.
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i debug the code.then i got below exception.



i got above exception in below line


why i am getting exception on that line?


below is logcat output

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't expect Android to have a c: drive. That's a Windows thing.

Take a look at the Android file storage page. For writing to an external directory, it shows code like this:


On my genymotion emulator the File directory was: /storage/emulated/0/Pictures
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i change the my class as below



Still i am getting Permission denied on below line


i have already added the below lines to manifest file


 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone tell me whhy it gives me permission error?
 
Irina Goble
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the error message?
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the method for creating file




below is i am getting in LogCat file

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Irina/All

can anyone please help me to do this ?
 
Irina Goble
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you check if the media is available? Here is a code snippet from the link that Jeanne gave you.
Plus it will be helpful if you print the full file name.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to checking state, note the paragraph starting with "Applications should not directly use this top-level directory,..." in the javadocs. That's effectively what you're doing, so you should fix that.
 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now its working fine.anyway i have one issue still.I need to write String array as a currently when i used below code it writes data as a row.how to change it to write as a column.

 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the API for the CSVWriter you are using?

Before you start coding, you should clearly define exactly what you want to do. Then you should read the API to see how it works. Then you should describe the steps (to yourself, in your native language, and on paper) needed to get what you want to a form the API expects. Then you should write code. This does mean a few things you need practice on:
1) Reading documentation
2) Thinking ahead

I am pretty sure if you do the simple thing and take just the code you have and print it out into a column instead of a row you will then have problems getting the rest of your data to match up to the row you need it to. So you need to understand the API, how it works, and what you need to do before you start coding.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic