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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:01:14+00:00 2026-06-15T23:01:14+00:00

Hi i am new to android and i have written the following code to

  • 0

Hi i am new to android and i have written the following code to draw a line chart . I am using a database to pass the values to the graph But the graph is not plotting.

Can you also tell me how to change the below code to draw a bar chart.

import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.TimeSeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.graphics.Color;
public class ChartActivity<BMICalculatorDB> extends Activity{

    public ChartActivity() {
        super();
    }
        public ChartActivity(Context context, String name, CursorFactory factory,
            int version, DatabaseErrorHandler errorHandler) {
        super();
        // TODO Auto-generated constructor stub
    }


        public static final String KEY_BMIID = "bmi_id";
        public static final String KEY_BMIDATA = "bmi_data";
        public static final String KEY_BMIDATE = "bmi_date";

        private static final String DATABASE_NAME = "Jayant";
        private static final String DATABASE_TABLE = "android_metadata";
        private static final int DATABASE_VERSION = 2;

        private DBHelper ourHelper;
        private static Context ourContext;
        private SQLiteDatabase ourDatabase;

        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 void BMICalculatorDB(Context c){
            ourContext = c;
        }

        @SuppressWarnings("unchecked")
        public BMICalculatorDB open(){
            ourHelper = new DBHelper(ourContext);
            ourDatabase = ourHelper.getWritableDatabase();
            return (BMICalculatorDB) 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("Bar1");
            TimeSeries series2 = new TimeSeries(title);

            getBMIDataData();

            while (!c.isAfterLast()) {
                int date = c.getInt((Integer) c.getColumnIndexOrThrow("DAYS"));
                int weight = c.getInt((Integer) c.getColumnIndexOrThrow("TOP 10"));
                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("Bar1");

            //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, "Bar Graph Title");

            return intent;

        }

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

        }

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

        }
    }
  • 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-15T23:01:15+00:00Added an answer on June 15, 2026 at 11:01 pm

    Just add an empty constructor and call super() from inside

    public ChartActivity() {
        super();
    }
    

    It should work. The problem is here:

    Caused by: java.lang.InstantiationException: can't instantiate class flu.solutions.travelsense.ChartActivity; no empty constructor
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i am new developer on android i have written code for display simple
I am a bit new with android but I have some java experience. So
i am creating a new android application.i am using the table layout. I have
Ok, im fairly new to android but i have managed to teach myself the
I have written following code to make a call also have set permissions in
I have written following code to get location name package demo.gps.locname; import java.io.IOException; import
I have the following Java code being used on an Android device that encrypts
I have the following method for my android program, written in Java. The method
I have written the following code with permissions included in the manifest file. package
I have the following bit of code, used on Android and tested quite extensively

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.