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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:46:40+00:00 2026-05-13T22:46:40+00:00

First I want to describe my situation briefly. I have two classes, one MainClass

  • 0

First I want to describe my situation briefly.

I have two classes, one MainClass and one DataBaseHelper class, which extends SQLiteOpenHelper.

From my MainClass I call a method in the DataBaseHelper class to open a data base. Before opening the data base I want to check the users data base version (this is important as soon as I want to update the data base and push it to the Android market). So from the DataBaseHelper class I call the following method, which is in the MainClass.

 public int checkCurrentDbVersion(){
        // Restore preferences
        SharedPreferences settings = getSharedPreferences(PREFERENCES, 0);
        int dbUpgradeVar = settings.getInt("dbUpgradeVar", 1);
        return dbUpgradeVar;        
    }

I call the checkCurrentDbVersion() method from the DataBaseHelper class like so:

    MainClass currentDbVersion = new MainClass(); 

    int oldDbVersion = currentDbVersion.checkCurrentDbVersion();

As soon as the debugger runs the following line, it stops.

SharedPreferences settings = getSharedPreferences(PREFERENCES, 0);

What am I doing wrong? I have no constructor defined. Could that be the failure?

Best Regards
Johe

  • 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-13T22:46:41+00:00Added an answer on May 13, 2026 at 10:46 pm

    I found a solution, which I wanna share. It can be found here:

    Passing data through intents instead of constructors

    I forgot the context (I am still not 100% sure what the context is all about, but anyways…).

    So to get the code working I changed it like so:

     public int checkCurrentDbVersion(Context context){
            // Restore preferences
            SharedPreferences settings = context.getSharedPreferences(PREFERENCES, 0);
            int dbUpgradeVar = settings.getInt("dbUpgradeVar", 1);
            return dbUpgradeVar;        
        }
    

    Call the method

    private final Context myContext;
    
    /*
    *do some other stuff here
    */
    
        MainClass currentDbVersion = new MainClass(); 
    
        int oldDbVersion = currentDbVersion.checkCurrentDbVersion(myContext);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first thing I want to know in between two algorithms which one is better
I have an object which I first want to rotate (about its own center)
Let me describe my situation first: I have a blog website, where the blog
I have a problem but first i want to know if im working on
hi i have two xml file and i want to bind grid view eith
Please help me to resolve the following problem: First of all, I have one
Situation: I have a C# program which does the following: Generate many files (replacing
I have some python module, which has a class ModuleClass and I can't modify
To describe my problem i have created a small application. At first the Usercontrol:
I'll try to describe the real situation. In our company we have a reservation

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.