Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6565815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:08:31+00:00 2026-05-25T14:08:31+00:00

i just started practicing android and sqlite database. i came across a very strange

  • 0

i just started practicing android and sqlite database. i came across a very strange problem which i am unable to rectify.kindly help me out.
Below i have out my DataBaseHelper class. (Description follows after the code block…)

package com.dialog.test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseHelper extends SQLiteOpenHelper{

//The Androids default system path of your application database.
private static String DB_PATH = "/data/data/com.dialog.test/databases/";

private static String DB_NAME = "butName";

private SQLiteDatabase myDataBase;

private final Context myContext;

public DataBaseHelper(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
}

//Create Database
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
//do nothing - database already exist
}else{
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}

//check Database
private boolean checkDataBase(){
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}catch(SQLiteException e){
//database doest exist yet.
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null;
}

private void copyDataBase() throws IOException{

//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;

//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);

//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}

//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();

}

public void openDataBase() throws SQLException{

//Open the database
String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

}

@Override
public synchronized void close() {

if(myDataBase != null)
myDataBase.close();

super.close();

}

@Override
public void onCreate(SQLiteDatabase db) {

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}

Now when i create an object for this class i get the following error

package com.dialog.test;

import java.io.IOException;

import android.database.SQLException;

public class VarbClass {
//syntax token error ";" in the below line
DataBaseHelper myDbHelper = new DataBaseHelper();
myDbHelper = new DataBaseHelper(this);
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
}catch(SQLException sqle){
throw sqle;
}
}

error on line 9 in the code above…
//syntax token error “;” in the below line
DataBaseHelper myDbHelper = new DataBaseHelper();
kindly help me resolve my issue thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:08:32+00:00Added an answer on May 25, 2026 at 2:08 pm

    The code of VarbClass is obviously wrong. The ‘try’ block should be inside a method or a ‘static’ block. Try this:

    public class VarbClass {
    DataBaseHelper myDbHelper;
    
    
    public VarbClass() {
        myDbHelper = new DataBaseHelper(this);
        try{
            myDbHelper.createDataBase();
        } 
        catch (IOException ioe) {
            throw new Error("Unable to create database");
        }
    
        try {
            myDbHelper.openDataBase();
        } 
        catch (SQLException sqle){
            throw sqle;
        }
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just started designing a database which I have not done before. And am wondering
Just started working with android and ran into a small problem. I am have
Just started with developing for WP7 and came across the following. I have a
I just started practicing TDD in my projects. I'm developing a project now using
Just started working with .NET and MVC(1). I'm having a problem wherein in my
I just started thinking about creating/customizing a web crawler today, and know very little
Just started learning Groovy, got the PragProg book Programming Groovy and had a problem
Just started exploring Cocoa so pretty much a total noob. I've written a very
I just started on a xml document just for practicing xslt and I have
Just started working with the Zend Framework Zf Tool and I've already come across

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.