Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
anta40
Posts: 224
Registered: ‎07-26-2010
My Device: Z10

Problem in modifying FileExplorerDemo

I'm tinkering with FileExplorerDemo (one of RIM's examples). Every time you run it, it will point to /store.

I'd like to change it, so it will point to SDCard/BlackBerry/documents.

 

So I take look at this part:

  FileExplorerDemoScreen() 
    {
        setTitle("File Explorer Demo");

        _list = new FileExplorerDemoListFieldImpl();
        add(_list);
        readRoots(null);
        
        _uiApp = (FileExplorerDemo)UiApplication.getUiApplication();
        _fileListener = new FileExplorerDemoJournalListener(this);        
        _uiApp.addFileSystemJournalListener(_fileListener);
        add(new ButtonField("Test", FOCUSABLE | ButtonField.CONSUME_CLICK | FIELD_HCENTER));
    }

 and change readRoots(null) into readRoots("SDCard") and readRoots("SDCard/")

neither of them work. I always get this error:

Connector.open() threw
net.rim.device.api.io.File.FileIOException:
File system error (1003)

 

Previously, I already enabled the "Use PC file system for SD card files", and I can browse through it using the built-in BB file explorer.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Problem in modifying FileExplorerDemo

can you post the code of readRoots?
If you ask a question about that specifically you should post the relevant code.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in modifying FileExplorerDemo

As Simon said, it would have been useful for you to actually provide the code that throws the error.

 

That said, it seems that you are using the standard FileExplorerDemo.  Unless you have actually mounted an SD Card to the Simulator you will get this error if you force it to try to read the SD Card.  SO make sure your Simulator has an SD Card before you do this. 

Developer
anta40
Posts: 224
Registered: ‎07-26-2010
My Device: Z10

Re: Problem in modifying FileExplorerDemo

[ Edited ]

Oh sorry, forgot about that.

/**
     * Reads the path that was passed in and enumerates through it
     * 
     * @param root Path to be read.
     */
    private void readRoots(String root)
    {
        _parentRoot = root;
        
        // Clear whats in the list.
        _list.removeAll();

        FileConnection fc = null;
        Enumeration rootEnum = null;

        if (root != null) 
        {
            // Open the file system and get the list of directories/files
            try 
            {                
                fc = (FileConnection)Connector.open("file:///" + root, Connector.READ);
                rootEnum = fc.list();
            } 
            catch (Exception ioex) 
            {
                FileExplorerDemo.errorDialog(ioex.toString());
            } 
            finally 
            {
                
                if (fc != null) 
                {   
                    // Everything is read, make sure to close the connection
                    try 
                    {
                        fc.close();
                        fc = null;
                    } 
                    catch (Exception ioex) 
                    {                        
                    }
                }
            }
        }

        // There was no root to read, so now we are reading the system roots
        if (rootEnum == null) 
        {
            rootEnum = FileSystemRegistry.listRoots();
        }

        // Read through the list of directories/files
        while (rootEnum.hasMoreElements()) 
        {
            String file = (String)rootEnum.nextElement();
            
            if (root != null) 
            {
                file = root + file;
            }
            
            readSubroots(file);
        }
    }

 And the SD card was already mounted before I ran the simulator.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Problem in modifying FileExplorerDemo

how to check if the card is available:
http://supportforums.blackberry.com/t5/Java-Development/Programmatically-determine-if-a-microSD-card...

how to save a file:
http://supportforums.blackberry.com/t5/Java-Development/Save-file-to-SDCard/m-p/218538#M32444
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter