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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:07:54+00:00 2026-06-14T10:07:54+00:00

I’m trying to display in graph my results of BMI. Data come from database.

  • 0

I’m trying to display in graph my results of BMI. Data come from database. Here’s what I have tried so far:

private static class DBHelper extends SQLiteOpenHelper{

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL( "CREATE TABLE " + DATABASE_TABLE + " (" +
        KEY_BMIID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_BMIDATA + " TEXT NOT NULL, " +
                KEY_BMIDATE + " TEXT NOT NULL );"
                );
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL( "DROP TABLE IF EXISTS " + DATABASE_TABLE );
        onCreate(db);
    }

}

public BMICalculatorDB(Context c){
    ourContext = c;
}

public BMICalculatorDB open(){
    ourHelper = new DBHelper(ourContext);
    ourDatabase = ourHelper.getWritableDatabase();
    return this;
}

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

public long createEntry( String data, String date ) {
    //, String date 
    // TODO Auto-generated method stub
    ContentValues cv = new ContentValues();
    cv.put(KEY_BMIDATA, data);
    cv.put(KEY_BMIDATE, date);
    return ourDatabase.insert(DATABASE_TABLE, null, cv);
}

public String getBMIID() {
    // TODO Auto-generated method stub
    String[] column =
            new String[]{ KEY_BMIID };
    Cursor c = 
            ourDatabase.query(DATABASE_TABLE, column, null, null, null, null, null);

    String result = "";
    int iID = c.getColumnIndex(KEY_BMIID);

    for ( c.moveToFirst(); ! c.isAfterLast(); c.moveToNext() ){
        result = result + c.getString(iID);
    }

    return result;
}

public String getBMIDataData(){

    String[] column =
                new String[]{ KEY_BMIDATA };
        Cursor c = 
                ourDatabase.query( DATABASE_TABLE, column, null, null, null, null, null );

        String result = "";
        int iData = c.getColumnIndex( KEY_BMIDATA );

        for ( c.moveToFirst(); ! c.isAfterLast(); c.moveToNext() ){
            result = result + c.getString( iData );
        }


    return result;
}

public String getBMIDateData(){
    String[] column =
            new String[]{ KEY_BMIDATE };
    Cursor c = 
            ourDatabase.query( DATABASE_TABLE, column, null, null, null, null, null );

    String result = "";
    int iDate = c.getColumnIndex( KEY_BMIDATE);

    for ( c.moveToFirst(); ! c.isAfterLast(); c.moveToNext() ){
        result = result + c.getString( iDate );
    }


return result;
}

public void updateEntry( long lId, String mData, String mDate ) {
    // TODO Auto-generated method stub
    ContentValues cvUpdate = new ContentValues();

    cvUpdate.put( KEY_BMIDATA, mData );
    cvUpdate.put( KEY_BMIDATE, mDate );
    ourDatabase.update( DATABASE_TABLE, cvUpdate, KEY_BMIID + " = lId", null );
}

public String getData(long l) {
    // TODO Auto-generated method stub
    return null;
}

public String getDate(long l) {
    // TODO Auto-generated method stub
    return null;
}

public XYMultipleSeriesDataset getDemoDataset(String title) {

    String[] column =
            new String[]{ KEY_BMIDATA };
    Cursor c = ourHelper.getWritableDatabase().query( DATABASE_TABLE, column, null, null, null, null, null );

    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

    TimeSeries series = new TimeSeries("Line1");
    TimeSeries series2 = new TimeSeries(title);

    getBMIDataData();

    while (!c.isAfterLast()) {
        int date = c.getInt((Integer) c.getColumnIndexOrThrow("bmi_date"));
        int weight = c.getInt((Integer) c.getColumnIndexOrThrow("bmi_data"));
        series2.add(weight, date);
        c.moveToNext();
    }

    c.close();

    dataset.addSeries(series);
    dataset.addSeries(series2);

    return dataset;
}


public Intent getIntent(Context context) {

    //Lager TimeSeries for den første linja
    XYMultipleSeriesDataset dataset = getDemoDataset("Line1");

    //Kode for render
    XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();

    //Optimalisering linje1
    XYSeriesRenderer renderer = new XYSeriesRenderer();
    renderer.setColor(Color.YELLOW);
    renderer.setPointStyle(PointStyle.CIRCLE);
    renderer.setFillPoints(true);

    // Optimalisering linje2 husk rekke følgen
    XYSeriesRenderer renderer2 = new XYSeriesRenderer();
    renderer2.setColor(Color.BLUE);
    renderer2.setPointStyle(PointStyle.SQUARE);
    renderer2.setFillPoints(true);

    //Legger til render seriene
    mRenderer.addSeriesRenderer(renderer);

    //Optimalisering grafen
    mRenderer.setChartTitle("Test");
    mRenderer.setZoomEnabled(true);
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setBackgroundColor(Color.BLACK);
    mRenderer.setApplyBackgroundColor(true);
    mRenderer.setXTitle("Dager");
    mRenderer.setShowGrid(true);

    mRenderer.addSeriesRenderer(renderer2);


    Intent intent = ChartFactory.getLineChartIntent(context, dataset, 
            mRenderer, "Line Graph Title");

    return intent;

}

I got errors in line:

        Cursor c = ourHelper.getWritableDatabase().query( DATABASE_TABLE, column, null, null, null, null, null );

        XYMultipleSeriesDataset dataset = getDemoDataset("Line1");

LogCat:

11-17 14:35:36.823: E/AndroidRuntime(334): FATAL EXCEPTION: main
11-17 14:35:36.823: E/AndroidRuntime(334): java.lang.NullPointerException
11-17 14:35:36.823: E/AndroidRuntime(334):  at com.fps.iHealthFirst.calculators.BMICalculatorDB.getDemoDataset(BMICalculatorDB.java:155)
11-17 14:35:36.823: E/AndroidRuntime(334):  at com.fps.iHealthFirst.calculators.BMICalculatorDB.getIntent(BMICalculatorDB.java:183)
11-17 14:35:36.823: E/AndroidRuntime(334):  at com.fps.iHealthFirst.calculators.BMICalculator.onClick(BMICalculator.java:161)

My Activity class:

public class BMICalculator extends Activity implements OnClickListener{

Button calculate, cancel, view;
EditText etweight, etheightin, etanswer, etheightft, etage;
TextView tvbmi;
RadioGroup gender;
RadioButton male, female;
Date dt = new Date();

public final String TABLE_NAME = "tbl_bmi";
public final String COLUMN_NAME = "bmi_data";

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_LEFT_ICON);
    setContentView(R.layout.bmi);
    getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.calculator32);

    // call for components
    initControls();     

} // end onCreate method

private void initControls(){

    calculate = (Button) findViewById (R.id.btBMICalculate);
    cancel = (Button) findViewById (R.id.btBMICancel);
    calculate.setOnClickListener(this);
    cancel.setOnClickListener(this);
    etweight = (EditText) findViewById (R.id.etBMIweight);
    etheightin = (EditText) findViewById (R.id.etBMIheightIn);
    etheightft = (EditText) findViewById (R.id.etBMIheightft);
    etanswer = (EditText) findViewById (R.id.etBMI);    
    etage = (EditText) findViewById (R.id.etBMIAge);
    tvbmi = (TextView) findViewById (R.id.tvBMI);
    tvbmi.setOnClickListener(this);
    male = (RadioButton) findViewById (R.id.rbMale);
    female = (RadioButton) findViewById (R.id.rbFemale);
    view = (Button) findViewById (R.id.btnViewMe);
    view.setOnClickListener(this);

}

private void viewErrorToast(){

     LayoutInflater inflater = getLayoutInflater();
     View layout = inflater.inflate(R.layout.alert_toast,
        (ViewGroup) findViewById(R.id.llToast));
     ImageView image = (ImageView) layout.findViewById(R.id.tvImageToast);
     image.setImageResource(R.drawable.alert32);
     TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);
     title.setText("Attention");
     TextView text = (TextView) layout.findViewById(R.id.tvTextToast);
     text.setText("You have blank field/s!");
     Toast toast = new Toast(getApplicationContext());
     toast.setGravity(Gravity.CENTER | Gravity.CENTER, 12, 40);
     toast.setDuration(Toast.LENGTH_SHORT);
     toast.setView(layout);
     toast.show();

} // end of viewErrorToast method


private void viewBMISavedToast(){

    boolean didItWork = true;

    try{
    String data = etanswer.getText().toString();
    String date = new SimpleDateFormat( "yyyy-MM-dd" ).format( dt );

    BMICalculatorDB entry = new BMICalculatorDB( BMICalculator.this );
    entry.open();

    entry.createEntry(data, date);

    entry.close();
    }
    catch(Exception e){
        didItWork = false;
        viewErrorToast();
    }finally{
        if (didItWork){

            AlertDialog.Builder builder = new AlertDialog.Builder( this );
            builder.setTitle( "Successful" )
            .setIcon( R.drawable.ic_launcher )
            .setMessage( "You're result is saved in the database!" )
            .setPositiveButton( "OK", new DialogInterface.OnClickListener() {           
                public void onClick( DialogInterface dialog, int which ) {

                    dialog.dismiss();
                }
            });       
         AlertDialog ad = builder.create();
         ad.show();  

        }

    }


}


public void onClick(View v) {
    // TODO Auto-generated method stub

    switch(v.getId()){
    case R.id.btBMICalculate:
        if (male.isChecked()){
            calculateMen();
        }
        else if (female.isChecked()){
            calculateWomen();
        } // end if else
        break;
    case R.id.btBMICancel:
        clearAll();
        break;
    case R.id.tvBMI:
        displayDialog();
        break;
    case R.id.btnViewMe:
        //Intent i = new Intent( BMICalculator.this, ViewBMIData.class );
        //startActivity(i);
        BMICalculatorDB view = new BMICalculatorDB( null );
        Intent viewIntent = view.getIntent( this );
        startActivity( viewIntent );
        break;
    } // end switch

} // end onClick method

I’ve got new logcat errors:

11-17 15:13:34.580: E/AndroidRuntime(360): FATAL EXCEPTION: main
11-17 15:13:34.580: E/AndroidRuntime(360): java.lang.IllegalArgumentException: column 'bmi_date' does not exist
11-17 15:13:34.580: E/AndroidRuntime(360):  at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:314)
11-17 15:13:34.580: E/AndroidRuntime(360):  at com.fps.iHealthFirst.calculators.BMICalculatorDB.getDemoDataset(BMICalculatorDB.java:165)
11-17 15:13:34.580: E/AndroidRuntime(360):  at com.fps.iHealthFirst.calculators.BMICalculatorDB.getIntent(BMICalculatorDB.java:183)
11-17 15:13:34.580: E/AndroidRuntime(360):  at com.fps.iHealthFirst.calculators.BMICalculator.onClick(BMICalculator.java:162)
11-17 15:13:34.580: E/AndroidRuntime(360):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

Can you help me figure out what I’m missing in here? I’ve been stuck with this problem for weeks. Any help is appreciated. thanks.

  • 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-14T10:07:56+00:00Added an answer on June 14, 2026 at 10:07 am

    you never opened your database for your intent method like you did for your entry method. In your button switch statement:

    case R.id.btnViewMe:
            BMICalculatorDB view = new BMICalculatorDB( BMICalculator.this );
            view.open(); //<-- missing this line!!!
            Intent viewIntent = view.getIntent( BMICalculator.this ); // <-- make sure this context is approriate
            startActivity( viewIntent );
            view.close();
            break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.