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
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Sqlite initialization failed: : out of memory

Hi All,

 

I am using SQLITE in my application but whenever i try to open database file. It gives me the following error.

 

 

db = DatabaseFactory.openOrCreate(uri, new DatabaseSecurityOptions(false));  

 

error comes at the above line.

 

net.rim.device.api.database.DatabaseIOException: Sqlite initialization failed: : out of memory

 

 

 

Please guide me.

 

Thanks 

Ekansh

Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: Sqlite initialization failed: : out of memory

where are you creating database SDCard/Store ??

 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Developer
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: Sqlite initialization failed: : out of memory

        public void openDB(String DB_NAME) {
                DBNAME = DB_NAME;
                try {
                        String dbLocation = "/SDCard/databases/";

                        // Determine if an SDCard is present
                        boolean sdCardPresent = false;
                        String root = null;
                        Enumeration e = FileSystemRegistry.listRoots();
                        while (e.hasMoreElements()) {
                                root = (String) e.nextElement();
                                if (root.equalsIgnoreCase("sdcard/")) {
                                        sdCardPresent = true;
                                }
                        }
                        if (!sdCardPresent) {
                                // If an SDCard is not available we will store our database in
                                // flash memory. This is not recommended for large databases.
                                dbLocation = "/store/home/user/";
                        }

                        URI uri = URI.create(dbLocation + DB_NAME);

                        // Open or create a plain text database. This will create the
                        // directory and file defined by the URI (if it does not already
                        // exist).
                        db = DatabaseFactory.openOrCreate(uri, new DatabaseSecurityOptions(
                                        false));

                        // Close the database in case it is blank and we need to write to
                        // the file
                        db.close();

                        // Open a connection to the database file
                        FileConnection fileConnection = (FileConnection) Connector
                                        .open("file://" + dbLocation + DB_NAME);

                        // If the file is blank, copy the pre-defined database from this
                        // module to the SDCard or flash memory.
                        if (fileConnection.exists() && fileConnection.fileSize() == 0) {
                                readAndWriteDatabaseFile(fileConnection);
                        }

                        // Open the database
                        db = DatabaseFactory.open(uri);
                } catch (Exception ex) {
                        System.out.println("Exception id Database Login openDB() :: "
                                        + ex.toString());
                }

        }

 I have posted my code.

Please see.

Developer
Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: Sqlite initialization failed: : out of memory

Went through your code it’s seemed fine & compare with the code. Can you plz check your sdcard or phone memory.

following is the sample example code

 

{
            String dbLocation = "/SDCard/databases/SQLite Demo/";
            
            // Create URI            
            URI uri = URI.create(dbLocation + DB_NAME);     
            
            // Open or create a plain text database.  This will create the
            // directory and file defined by the URI (if they do not already exist).
            Database db = DatabaseFactory.openOrCreate(uri, new DatabaseSecurityOptions(false));  
            
            // Close the database in case it is blank and we need to write to the file
            db.close();
            
            // Open a connection to the database file        
            FileConnection fileConnection = (FileConnection)Connector.open("file://" + dbLocation + DB_NAME);    
            
            // If the file is blank, copy the pre-defined database from this
            // module to the SDCard.
            if(fileConnection.exists() && fileConnection.fileSize() == 0)
            {                      
                readAndWriteDatabaseFile(fileConnection);           
            }         
            
            // Retrieve the code signing key for the XYZ key file
            CodeSigningKey codeSigningKey = CodeSigningKey.get(CodeModuleManager.getModuleHandle( "SQLiteDemo" ), "XYZ");
            
            try
            {
                // Encrypt and protect the database.  If the database is already
                // encrypted, the method will exit gracefully.
                DatabaseFactory.encrypt(uri, new DatabaseSecurityOptions(codeSigningKey));
            }
            catch(DatabaseException dbe)
            {
                errorDialog("Encryption failed - " + dbe.toString());         
            }
            
            // Create a new DatabaseOptions object forcing foreign key constraints
            DatabaseOptions databaseOptions = new DatabaseOptions();
            databaseOptions.set( "foreign_key_constraints", "on" );
            
            // Open the database            
            db = DatabaseFactory.open(uri, databaseOptions);
            
            // Create a new main screen and push it onto the display stack        
            SQLiteDemoScreen screen = new SQLiteDemoScreen(new SQLManager(db));        
            pushScreen(screen);                          
        }

 

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
New Contributor
Posts: 5
Registered: ‎08-23-2012
My Device: Blackberry 9800
My Carrier: Blackberry

Re: Sqlite initialization failed: : out of memory

THANKU
Highlighted
Developer
Posts: 49
Registered: ‎08-13-2012
My Device: 9300
My Carrier: Airtel

Re: Sqlite initialization failed: : out of memory

I've tried many things. Even my previous projects are also working fine. But the current case is something new to me. I am also not able to find the solution.

Thanks
Ekansh