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 8475589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:56:04+00:00 2026-06-10T17:56:04+00:00

I looked in the Context information and it says in the Known Indirect Subclasses

  • 0

I looked in the Context information and it says in the Known Indirect Subclasses for Activity Group, “This class is deprecated. Use the new Fragment and FragmentManager APIs instead” So why in the code below will it not work in my class that extends ListFragment? When I tried in my class that extends Activity though it works (which it should since its in the Known Indirect Subclasses). What would I need to do so I can open the database and get information inside of AFragmentTab? Thank you in advance and please if possible post code.

DataBaseHelper Class:

public class DataBaseHelper extends SQLiteOpenHelper{

private static String DB_PATH = "/data/data/com.example.alotoftesting/databases/";    
private static String DB_NAME = "library1_dev.db"; 
private SQLiteDatabase myDataBase;  
private final Context myContext;
Cursor cursor;


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

public void createDataBase() throws IOException{

    boolean dbExist =  checkDataBase();

    if(dbExist){
        //do nothing since the database already exist.
        System.out.println("Database Exist");
    }
    else{
        System.out.println("2.5");
        this.getReadableDatabase();

        try{
            System.out.println("3.");
            copyDataBase();
            System.out.println("We just copied the database.");
        }catch(IOException e){
            throw new Error("Error Copying Database");
        }
    }       
}

private boolean checkDataBase(){

    SQLiteDatabase checkDB = null;
    System.out.println("1.");
    try{
        String myPath = DB_PATH + DB_NAME;
        System.out.println("2.");
        checkDB =  SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
        System.out.println("We are in here");
    }catch(SQLiteException e){
        //database doesn't exist yet.
    }

    if(checkDB != null){
        checkDB.close();
        System.out.println("Database Closed");

    }

    return checkDB != null ? true : false;
}

private void copyDataBase()throws IOException{

    //Opens 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;

    //Opens the empty DB as the output stream.
    OutputStream myOutput = new FileOutputStream(outFileName);

    //transfer bytes from the inputfile to the outputfiles.
    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);
}    

public void closeDatabase() throws SQLException{

    //Close the database.
    myDataBase.close();
}

public ArrayList<String> getTableColumn(String tableName, String[] column){

    ArrayList<String> aL = new ArrayList<String>();

    cursor = myDataBase.query(tableName, column, null, null, null, null, null);

    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
      aL.add(cursor.getString(0));
      cursor.moveToNext();
    }

    System.out.println(aL);
    cursor.close();
    return aL;
}

@Override
public void onCreate(SQLiteDatabase db){

}

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

}


}

The class I want to open the database in, AFragmentTab Class:

public class AFragmentTab extends ListFragment{

DataBaseHelper myDB;

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);

    myDB = new DataBaseHelper(this);  //<------The error is here.   
}
}
  • 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-10T17:56:06+00:00Added an answer on June 10, 2026 at 5:56 pm

    Fragment doesn’t extend Activity and indirectly Context. So change your code as below:

    myDB = new DataBaseHelper(getActivity());
    

    The method getActivity() returns reference of the activity your fragment is attached to, hence providing solution to pass context.

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

Sidebar

Related Questions

Base information: This is in context to the indexing process of OpenStreetMap data. To
Context I've looked at the top three results on Google for Clojure, Ring, SSL,
I looked around but haven't found an answer to this. I have a CentOS
I looked around and couldn't find it! Maybe I didn't look hard enough,but this
I looked at this: Returning values from nested functions in Javascript but it did
I'm reading a lot of conflicting information on this topic, so going to ask
I'm new to Django and MVT, so I apologize if this is a silly
Okay I've tried multiple things and looked for answers to this and I can't
The two paragraphs after this are background information in case I'm thinking of this
I've looked all over for any answer on this and haven't been able to

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.