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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:36:21+00:00 2026-06-18T03:36:21+00:00

I’m developing a simple android application that stores current(now) date into sqlite database. Later

  • 0

I’m developing a simple android application that stores current(now) date into sqlite database.
Later it retrieve the date values from the database to an activity and plot them on the line chart with some values assigned to dates.
I have done all the coding like retrieving the saved dates from database and storing them to a ArrayList, coding for the line chart and everything. Finally I’m getting a nullpointer exception. kindly take a look at my code and provide a solution. It would be a simple task to find the exception in the program.

Here is the layout xml code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add Date" 
            android:layout_weight="1"/>

        <Button
            android:id="@+id/chartButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Chart" 
            android:layout_weight="1"/>
    </LinearLayout>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

chartButton is for showing the graph using the intent.

Here is the part of the code for line chart:

public void openChart() {
        // TODO Auto-generated method stub
        //Date[] dt = new Date[c.getCount()];
        //int i=0;
        c=dbAdapter.getAllRecords();
        c.moveToFirst();
        List<Date> dt = new ArrayList<Date>();

        while(c.moveToNext()){
            String stringDate = c.getString(1);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = null;
            try {
                date = sdf.parse(stringDate);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            dt.add(date);//dt[i] = date;
            //i++;
        }

        Double[] numbers = null; //= {20.0,20.1,20.2,20.3,20.4,20.5,20.6,20.7,20.8,20.9,21.0,21.2};

        TimeSeries numbersTime = new TimeSeries("Numbers Time");

        for(int i2=0;i2<dt.size();i2++){
            numbers[i2]=(double) i2;
            numbersTime.add(dt.get(i2),numbers[i2]);
        }

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        dataset.addSeries(numbersTime);


        XYSeriesRenderer numbersRenderer = new XYSeriesRenderer();
        numbersRenderer.setColor(Color.BLACK);
        numbersRenderer.setPointStyle(PointStyle.CIRCLE);
        numbersRenderer.setFillPoints(true);
        numbersRenderer.setLineWidth(2);
        numbersRenderer.setDisplayChartValues(true);

        XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();

         multiRenderer.setChartTitle("Visits vs Views Chart");
         multiRenderer.setXTitle("Date Time");
         multiRenderer.setYTitle("Double Numbers");
         multiRenderer.setZoomButtonsVisible(true);

         multiRenderer.addSeriesRenderer(numbersRenderer);

         // Creating an intent to plot line chart using dataset and multipleRenderer
            Intent intent = ChartFactory.getLineChartIntent(getBaseContext(), dataset, multiRenderer);


            // Start Activity
            startActivity(intent);
    }

Here is the Cursor method in the DBAdapter class:

Cursor getAllRecords(){
        String[] columns = {COL_ID,COL_DATE};
        return db.query(TABLE_NAME, columns, null, null, null, null, null); 
    }

Here is the Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.dateexample.seenu"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.dateexample.seenu.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity android:name="org.achartengine.GraphicalActivity" />
    </application>

</manifest>

Here is the LogCat report:

01-25 18:11:39.656: D/AndroidRuntime(28121): Shutting down VM
01-25 18:11:39.656: W/dalvikvm(28121): threadid=1: thread exiting with uncaught exception (group=0x40018578)
01-25 18:11:39.992: E/AndroidRuntime(28121): FATAL EXCEPTION: main
01-25 18:11:39.992: E/AndroidRuntime(28121): java.lang.NullPointerException
01-25 18:11:39.992: E/AndroidRuntime(28121):    at com.example.dateexample.seenu.MainActivity.openChart(MainActivity.java:103)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at com.example.dateexample.seenu.MainActivity$2.onClick(MainActivity.java:70)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.view.View.performClick(View.java:2485)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.view.View$PerformClick.run(View.java:9080)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.os.Handler.handleCallback(Handler.java:587)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.os.Looper.loop(Looper.java:130)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.app.ActivityThread.main(ActivityThread.java:3687)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at java.lang.reflect.Method.invokeNative(Native Method)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at java.lang.reflect.Method.invoke(Method.java:507)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at dalvik.system.NativeStart.main(Native Method)
01-25 18:11:39.992: E/AndroidRuntime(28121): FATAL EXCEPTION: main
01-25 18:11:39.992: E/AndroidRuntime(28121): java.lang.NullPointerException
01-25 18:11:39.992: E/AndroidRuntime(28121):    at com.example.dateexample.seenu.MainActivity.openChart(MainActivity.java:103)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at com.example.dateexample.seenu.MainActivity$2.onClick(MainActivity.java:70)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.view.View.performClick(View.java:2485)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.view.View$PerformClick.run(View.java:9080)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.os.Handler.handleCallback(Handler.java:587)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.os.Looper.loop(Looper.java:130)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at android.app.ActivityThread.main(ActivityThread.java:3687)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at java.lang.reflect.Method.invokeNative(Native Method)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at java.lang.reflect.Method.invoke(Method.java:507)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-25 18:11:39.992: E/AndroidRuntime(28121):    at dalvik.system.NativeStart.main(Native Method)

And finally I’m getting null pointerException showing in the logCat.
Once again I request kindly provide some solution for me.

  • 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-18T03:36:22+00:00Added an answer on June 18, 2026 at 3:36 am

    You have a unitialized array (Double[] numbers = null;) that you are attempting to add values to. you need to allocate numbers array prior to adding values to it.

    Double[] numbers = new Double[100];

    note: you might want to look into more flexible storage containers (Vectors, ArrayList, etc) that grow as you add to them.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am using JSon response to parse title,date content and thumbnail images and place

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.