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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:25:44+00:00 2026-06-03T04:25:44+00:00

I am trying to call a function in another one but I get a

  • 0

I am trying to call a function in another one but I get a nullpointerException as well as many other errors..

public float maxFat() {

    SharedPreferences customSharedPreference = getSharedPreferences(
            "myCustomSharedPrefs", Activity.MODE_PRIVATE);

    float cals = customSharedPreference.getFloat("calpref", 0f);
    float maxfat = cals / 36;

    return maxfat;
}

And here is where i call it

public XYMultipleSeriesDataset getFatDataset() {

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    Cursor c = database.rawQuery("select * from dailystats;", null);
    float i = 1.0f;

    c.moveToFirst();
    XYSeries seriesFat = new XYSeries("Fat");
    XYSeries seriesMaxFat= new XYSeries("Maximum Fat");
    while (!c.isAfterLast()) {
        seriesFat.add(i++, c.getDouble(2));
        StatsActivity stats= new StatsActivity();
        seriesMaxFat.add(i, stats.maxFat());
        c.moveToNext();
    }
    dataset.addSeries(seriesFat);
    dataset.addSeries(seriesMaxFat);
    return dataset;
}

Here is the log file

05-05 11:39:22.737: E/AndroidRuntime(31282): java.lang.NullPointerException
05-05 11:39:22.737: E/AndroidRuntime(31282):    at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:153)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at com.nutriapp.StatsActivity.maxFat(StatsActivity.java:183)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at com.nutriapp.DatabaseAdapter.getFatDataset(DatabaseAdapter.java:396)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at com.nutriapp.FatActivity.getIntent(FatActivity.java:52)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at com.nutriapp.StatsActivity$1.onClick(StatsActivity.java:127)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at android.view.View.performClick(View.java:3511)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at android.view.View$PerformClick.run(View.java:14105)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at android.os.Handler.handleCallback(Handler.java:605)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at android.os.Looper.loop(Looper.java:137)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at android.app.ActivityThread.main(ActivityThread.java:4424)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at java.lang.reflect.Method.invoke(Method.java:511)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-05 11:39:22.737: E/AndroidRuntime(31282):    at dalvik.system.NativeStart.main(Native Method)
05-05 11:39:22.937: D/dalvikvm(31282): GC_CONCURRENT freed 135K, 3% free 9633K/9863K, paused 17ms+29ms
05-05 11:39:23.047: E/SQLiteDatabase(31282): close() was never explicitly called on database '/data/data/com.nutriapp/databases/nutriwellness.db' 
05-05 11:39:23.047: E/SQLiteDatabase(31282): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1943)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1007)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1051)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:770)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at com.nutriapp.DatabaseAdapter.open(DatabaseAdapter.java:215)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at com.nutriapp.FatActivity.getIntent(FatActivity.java:49)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at com.nutriapp.StatsActivity$1.onClick(StatsActivity.java:127)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.view.View.performClick(View.java:3511)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.view.View$PerformClick.run(View.java:14105)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.os.Handler.handleCallback(Handler.java:605)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.os.Looper.loop(Looper.java:137)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at android.app.ActivityThread.main(ActivityThread.java:4424)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at java.lang.reflect.Method.invokeNative(Native Method)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at java.lang.reflect.Method.invoke(Method.java:511)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-05 11:39:23.047: E/SQLiteDatabase(31282):    at dalvik.system.NativeStart.main(Native Method)
05-05 11:39:23.047: E/System(31282): Uncaught exception thrown by finalizer
05-05 11:39:23.098: E/System(31282): java.lang.IllegalStateException: Don't have database lock!
05-05 11:39:23.098: E/System(31282):    at android.database.sqlite.SQLiteDatabase.verifyLockOwner(SQLiteDatabase.java:2090)
05-05 11:39:23.098: E/System(31282):    at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2182)
05-05 11:39:23.098: E/System(31282):    at android.database.sqlite.SQLiteDatabase$1.entryRemoved(SQLiteDatabase.java:2178)
05-05 11:39:23.098: E/System(31282):    at android.util.LruCache.trimToSize(LruCache.java:197)
05-05 11:39:23.098: E/System(31282):    at android.util.LruCache.evictAll(LruCache.java:285)
05-05 11:39:23.098: E/System(31282):    at android.database.sqlite.SQLiteDatabase.deallocCachedSqlStatements(SQLiteDatabase.java:2143)
05-05 11:39:23.098: E/System(31282):    at android.database.sqlite.SQLiteDatabase.closeClosable(SQLiteDatabase.java:1126)
05-05 11:39:23.098: E/System(31282):    at android.database.sqlite.SQLiteDatabase.finalize(SQLiteDatabase.java:1914)
05-05 11:39:23.098: E/System(31282):    at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:182)
05-05 11:39:23.098: E/System(31282):    at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)
05-05 11:39:23.098: E/System(31282):    at java.lang.Thread.run(Thread.java:856)
  • 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-03T04:25:45+00:00Added an answer on June 3, 2026 at 4:25 am

    Does the class StatsActivity extend Activity? If so, you cannot use the new keyword to create a new instance of the class, and you need to rethink your application design.

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

Sidebar

Related Questions

I am trying to call a function in another .php file from this one
I'm trying to call a function from inside the call of another function. If
I am trying to call my function named isUrgencyTypeValid from my javascript code but
I'm trying to multicore a function (in Windows), which, at one point, calls another
I am trying to call a page with ajax, but from another server. This
I'm trying to use a Class_B function in one of Class_A's functions. But a
I'm trying to integrate one function into another function and am puzzled. What I'm
I'm trying to call a function in a Python script from my main C++
I'm trying to call a function from a form within the same .php file,
I'm trying to call a function that contains jQuery code. I want this function

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.