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

  • SEARCH
  • Home
  • 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 9070131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:36:36+00:00 2026-06-16T17:36:36+00:00

I have a very weird problem I am writing a code that gets data

  • 0

I have a very weird problem I am writing a code that gets data from database to show it in listView, so I’ve made a class for getting the database and other one for the adapter.
But when I run it on device I got no such table error, although it’s working fine on emulator. Also, I tried this code with another database in the same project and it’s working. I added the android_metadata table to them, but still not working.

This is my db class

public class Directory_DB extends SQLiteOpenHelper{

private static String TAG = "DataBaseHelper"; // Tag just for the LogCat window
//destination path (location) of our database on device
private static String DB_PATH = ""; 
private static String DB_NAME ;// Database name
private SQLiteDatabase mDataBase; 
private final Context mContext;
private String TABLE_NAME;

public Directory_DB(Context context , String DB_NAME ) 
{
    super(context , DB_NAME, null , 2);// 1? its Database Version
    DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
    this.mContext = context;
    this.DB_NAME = DB_NAME;

}   

public void createDataBase() throws IOException
{
    //If database not exists copy it from the assets

    boolean mDataBaseExist = checkDataBase();
    if(!mDataBaseExist)
    {
        this.getReadableDatabase();
        this.close();
        try 
        {
            //Copy the database from assests
            copyDataBase();
            Log.e(TAG, "createDatabase database created");
        } 
        catch (IOException mIOException) 
        {
            throw new Error("ErrorCopyingDataBase");
        }
    }
}
    //Check that the database exists here: /data/data/your package/databases/Da Name
    private boolean checkDataBase()
    {
        File dbFile = new File(DB_PATH + DB_NAME);
        Log.v("dbFile", dbFile + "   "+ dbFile.exists());
        return dbFile.exists();
    }

    //Copy the database from assets
    private void copyDataBase() throws IOException
    {
        InputStream mInput = mContext.getAssets().open(DB_NAME);
        String outFileName = DB_PATH + DB_NAME;
        OutputStream mOutput = new FileOutputStream(outFileName);
        byte[] mBuffer = new byte[1024];
        int mLength;
        while ((mLength = mInput.read(mBuffer))>0)
        {
            mOutput.write(mBuffer, 0, mLength);
        }
        mOutput.flush();
        mOutput.close();
        mInput.close();
    }

    //Open the database, so we can query it
    public boolean openDataBase() throws SQLException
    {
        String mPath = DB_PATH + DB_NAME;
        //Log.v("mPath", mPath);
        mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.CREATE_IF_NECESSARY);
        //mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
        return mDataBase != null;
    }

    @Override
    public synchronized void close() 
    {
        if(mDataBase != null)
            mDataBase.close();
        super.close();
    }




@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub

}

}

and this is my adapter class

public class DirectoryAdapter {
public static final String TAG_ID = "_id";
public static String TAG_TABLE_NAME;

protected static final String TAG = "DataAdapter";

private final Context mContext;
private SQLiteDatabase mDb;
private Directory_DB mDbHelper;

public DirectoryAdapter(Context context, String DB_NAME, String TABLE_NAME) {
    this.mContext = context;
    mDbHelper = new Directory_DB(mContext, DB_NAME );
    this.TAG_TABLE_NAME = TABLE_NAME;
    Log.d("Database name in adapter", DB_NAME);
    Log.d("Table name in adapter", TAG_TABLE_NAME);
}

public DirectoryAdapter createDatabase() throws SQLException {
    try {
        mDbHelper.createDataBase();
    } catch (IOException mIOException) {
        Log.e(TAG, mIOException.toString() + "  UnableToCreateDatabase");
        throw new Error("UnableToCreateDatabase");
    }
    return this;
}

public DirectoryAdapter open() throws SQLException {
    try {
        mDbHelper.openDataBase();
        mDbHelper.close();
        mDb = mDbHelper.getReadableDatabase();
    } catch (SQLException mSQLException) {
        Log.e(TAG, "open >>" + mSQLException.toString());
        throw mSQLException;
    }
    return this;
}

public void close() {
    mDbHelper.close();
}

public Cursor getTestData() {
    try {

        String sql = "SELECT * FROM " + TAG_TABLE_NAME;
        Cursor mCur = mDb.rawQuery(sql, null);

        return mCur;
    } catch (SQLException mSQLException) {
        Log.e(TAG, "getTestData >>" + mSQLException.toString());
        throw mSQLException;
    }
}

}

  • 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-06-16T17:36:37+00:00Added an answer on June 16, 2026 at 5:36 pm

    You can uninstall the appliation from the device and run it again.If you added a table on the database later it will not be reflected since your database is already created and table is created only when database is created.

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

Sidebar

Related Questions

I have a very weird problem that I can't understand. This is C code:
So I have a very weird problem. I am writing some code in VB.Net
I have a very weird problem using OpenMP in my C++ code: void update(double
I have a very weird problem in the most simple piece of VB.NET code:
I'm experiencing a (for me) very weird problem in Python. I have a class
I have a very weird problem, when storing my session in Memcached. From time
I have a very weird problem.That my web project deployed to the Weblogic 10.0,Monday
I have a very weird problem that when I call the method of a
Today, i have very weird problem with trim function. Here is my code. =and
I have a very weird problem. I have a VB.NET 2.0 application that takes

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.