开发者

Reading an excel sheet for android program

开发者 https://www.devze.com 2023-02-27 06:20 出处:网络
Im trying to read an excel sheet for an android app using eclipse workspace. I\'m putting the file path but it seems that is not even finding it. Do I need to declare the path of the file somewhere?

Im trying to read an excel sheet for an android app using eclipse workspace. I'm putting the file path but it seems that is not even finding it. Do I need to declare the path of the file somewhere?

Below is my code. Thank you for your help!

public void onCreate(Bundle savedInstanceState) {
        vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);   // calls VIBRATOR_SERVICE when button is pressed
        screensize = getScreenSize();
        setTheme(android.R.style.Theme_Translucent_NoTitleBar);
        super.onCreate(savedInstanceState);

        Eula.show(this);    // displays the EULA and asks user to Accept or Don't Accept

        try{
            fs = new FileInputStream(new File("/Users/paul/Desktop/CollegeTrack/Samp.xls"));
            InputStream fileinput = fs;
            try{
                Workbook workbook = Workbook.getWorkbook(fileinput);
                sheet = workbook.getSheet(0);
                database_array = Database.classDatabase(sheet); //stores each row in an array
                workbook.close();

            }
      开发者_JAVA技巧      catch (BiffException e) {
                e.printStackTrace();
            }
                catch (IOException e) {
                e.printStackTrace();
            }
        fs.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
            savedAssignments_array = Database.assignmentDatabase();
            savedCourses_array = Database.savedCourses();
            goToWelcomeScreen();
        }


It's probably failing because of the path you're using:

fs = new FileInputStream(new File("/Users/paul/Desktop/CollegeTrack/Samp.xls"));

I assume this points to a file on your computer somewhere, since it's got "Desktop" in the path. Your emulator is running an entirely separate OS (Android) and it has no concept of where this file is. In order to access it you'll need to either 1) Transfer the file to the emulator's storage or 2) Establish a shared network connection between the two.

Think about it in terms of an actual phone: You can't point your phone to a file on your desktop. It's a self-contained independent device. The emulator is exactly like this, it just happens to be running on top of your computer's OS.

0

精彩评论

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