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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:53:03+00:00 2026-06-14T12:53:03+00:00

I’m a noob to android development and I am trying to display a pie

  • 0

I’m a noob to android development and I am trying to display a pie chart in a dialog. However, I cannot get the piechart to display. I used the XYChartBuilder.java as my guide as suggested by this SO question here. I used the achart demo xychart.xml to test my layout design and it worked perfectly with the demo. But when i try to use the same xml configuration with my application i get an nullpointerexception saying android.graphics.Canvas.throwIfRecycled. The only change i made was to instantiate the ChartView when the dialog is opened via layoutinflater as opposed to during onResume in the demo. When i change the chart linearlayout from a defined height of 200dp to “wrap_content” the exception isn’t thrown. I have included activity android:name=”org.achartengine.GraphicalActivity” /> in my manifest so that isn’t the problem. The issue has to be something with the dialog. Any help is greatly appreciated.

MY XML

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

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

    <com.activity.GSCC.SegmentedRadioGroup
        android:id="@+id/segment_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:checkedButton="@+id/button_one"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@id/button_one"
            android:layout_weight="0.25"
            android:button="@null"
            android:gravity="center"
            android:minHeight="33dip"
            android:minWidth="40dip"
            android:text="Ledger"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/radio_colors" />

        <RadioButton
            android:id="@+id/button_two"
            android:layout_weight="0.25"
            android:button="@null"
            android:gravity="center"
            android:minHeight="33dip"
            android:minWidth="40dip"
            android:text="Chart"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/radio_colors" />
    </com.activity.GSCC.SegmentedRadioGroup>
</LinearLayout>

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TableLayout
            android:id="@+id/tableLayout1"
            android:layout_width="fill_parent"
            android:layout_height="105dp" >

            <TableRow>

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="Coin"
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="Qty."
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="Oz."
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" />

                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="Value"
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" />
            </TableRow>

            <TableRow>

                <TextView
                    android:id="@+id/tvcurrentcoin"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:ellipsize="none"
                    android:maxWidth="100dp"
                    android:text="CurrentCoin"
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" >
                </TextView>

                <TextView
                    android:id="@+id/tvcurrentqty"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="CurrentQuantity"
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" />

                <TextView
                    android:id="@+id/tvcurrentoz"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="CurrentOunces"
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" >
                </TextView>

                <TextView
                    android:id="@+id/tvcurrentvalue"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="CurrentValue"
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" >
                </TextView>
            </TableRow>

            <TableRow>

                <TextView
                    android:id="@+id/nothing2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:ellipsize="none"
                    android:maxWidth="100dp"
                    android:text=""
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" >
                </TextView>

                <TextView
                    android:id="@+id/nothing"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text=""
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" />

                <TextView
                    android:id="@+id/tvTotalValue"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="TOTAL:"
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" >
                </TextView>

                <TextView
                    android:id="@+id/tvportfoliovalue"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="1"
                    android:text="CurrentValue"
                    android:textColor="#FFFFFF"
                    android:textSize="12dp" >
                </TextView>
            </TableRow>
        </TableLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/add_values" />

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TableRow>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="5dip"
                    android:text="@string/x" />

                <EditText
                    android:id="@+id/xValue"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:enabled="false" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="5dip"
                    android:text="@string/y" />

                <EditText
                    android:id="@+id/yValue"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:enabled="false" />

                <Button
                    android:id="@+id/add"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:enabled="false"
                    android:text="@string/add" />
            </TableRow>
        </TableLayout>

        <LinearLayout
            android:id="@+id/chart"
            android:layout_width="fill_parent"
            android:layout_height="200dp" //Doesn't throw exception when set to "wrap content"
            android:layout_weight="1"
            android:orientation="horizontal" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/new_series"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/new_series" />
        </LinearLayout>

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

            <Spinner
                android:id="@+id/spinneradd"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.77" />
        </LinearLayout>

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

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

                <Spinner
                    android:id="@+id/spinnermodify"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.70" />
            </LinearLayout>
        </LinearLayout>

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

            <Spinner
                android:id="@+id/spinnerdelete"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.77" />
        </LinearLayout>

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

            <Spinner
                android:id="@+id/spinnerchange"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1.40" />
        </LinearLayout>

        <Button
            android:id="@+id/bSQLdeleteall"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Delete All Entries" />
    </LinearLayout>
</ScrollView>

MY CODE

LayoutInflater layoutInflater = getLayoutInflater();
View view=layoutInflater.inflate(R.layout.sqliteexample2,null);

//CHART ADDITIONS
            if (mChartView == null) {
                  piechartlayout = (LinearLayout) view.findViewById(R.id.chart);
                  mChartView = ChartFactory.getLineChartView(Activity.this, mDataset, mRenderer);
                  mRenderer.setClickEnabled(true);
                  mRenderer.setSelectableBuffer(100);                     
                  mChartView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                      SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
                      double[] xy = mChartView.toRealPoint(0);
                      if (seriesSelection == null) {
                        Toast.makeText(Activity.this, "No chart element was clicked", Toast.LENGTH_SHORT)
                            .show();
                      } else {
                        Toast.makeText(Activity.this,
                            "Chart element in series index " + seriesSelection.getSeriesIndex()
                                + " data point index " + seriesSelection.getPointIndex() + " was clicked"
                                + " closest point value X=" + seriesSelection.getXValue() + ", Y=" + seriesSelection.getValue()
                                + " clicked point value X=" + (float) xy[0] + ", Y=" + (float) xy[1], Toast.LENGTH_SHORT).show();
                      }
                    }
                  });
                  mChartView.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                      SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
                      if (seriesSelection == null) {
                        Toast.makeText(Activity.this, "No chart element was long pressed",
                            Toast.LENGTH_SHORT);
                        return false; // no chart element was long pressed, so let something
                        // else handle the event
                      } else {
                        Toast.makeText(Activity.this, "Chart element in series index "
                            + seriesSelection.getSeriesIndex() + " data point index "
                            + seriesSelection.getPointIndex() + " was long pressed", Toast.LENGTH_SHORT);
                        return true; // the element was long pressed - the event has been
                        // handled
                      }
                    }
                  });
                  mChartView.addZoomListener(new ZoomListener() {
                    public void zoomApplied(ZoomEvent e) {
                      String type = "out";
                      if (e.isZoomIn()) {
                        type = "in";
                      }
                      System.out.println("Zoom " + type + " rate " + e.getZoomRate());
                    }

                    public void zoomReset() {
                      System.out.println("Reset");
                    }
                  }, true, true);
                  mChartView.addPanListener(new PanListener() {
                    public void panApplied() {
                      System.out.println("New X range=[" + mRenderer.getXAxisMin() + ", " + mRenderer.getXAxisMax()
                          + "], Y range=[" + mRenderer.getYAxisMax() + ", " + mRenderer.getYAxisMax() + "]");
                    }
                  });
                  piechartlayout.addView(mChartView, new LayoutParams(LayoutParams.WRAP_CONTENT,
                      LayoutParams.WRAP_CONTENT));
                  boolean enabled = mDataset.getSeriesCount() > 0;
                  setSeriesEnabled(enabled);
                } else {
                  mChartView.repaint();
                }

            //////CHART ADDITIONS
                    mX = (EditText) view.findViewById(R.id.xValue);
                    mX.setEnabled(true);
                    mY = (EditText) view.findViewById(R.id.yValue);
                    mY.setEnabled(true);
                    mRenderer.setApplyBackgroundColor(true);
                    mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
                    mRenderer.setAxisTitleTextSize(16);
                    mRenderer.setChartTitleTextSize(20);
                    mRenderer.setLabelsTextSize(15);
                    mRenderer.setLegendTextSize(15);
                    mRenderer.setMargins(new int[] { 20, 30, 15, 0 });
                    mRenderer.setZoomButtonsVisible(true);
                    mRenderer.setPointSize(10);
                    mRenderer.setInScroll(true);

                    mAdd = (Button) view.findViewById(R.id.add);
                    mAdd.setEnabled(true);
                    mNewSeries = (Button) view.findViewById(R.id.new_series);
                    mNewSeries.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View v) {
                        String seriesTitle = "Series " + (mDataset.getSeriesCount() + 1);
                        XYSeries series = new XYSeries(seriesTitle);
                        mDataset.addSeries(series);
                        mCurrentSeries = series;
                        XYSeriesRenderer renderer = new XYSeriesRenderer();
                        mRenderer.addSeriesRenderer(renderer);
                        renderer.setPointStyle(PointStyle.CIRCLE);
                        renderer.setFillPoints(true);
                        mCurrentRenderer = renderer;
                        setSeriesEnabled(true);
                      }
                    });


                    mAdd.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View v) {
                        double x = 0;
                        double y = 0;
                        try {
                          x = Double.parseDouble(mX.getText().toString());
                        } catch (NumberFormatException e) {
                          // TODO
                          mX.requestFocus();
                          return;
                        }
                        try {
                          y = Double.parseDouble(mY.getText().toString());
                        } catch (NumberFormatException e) {
                          // TODO
                          mY.requestFocus();
                          return;
                        }
                        mCurrentSeries.add(12, 0);
                        mX.setText("");
                        mY.setText("");
                        mX.requestFocus();
                        if (mChartView != null) {
                          mChartView.repaint();
                        }
                        Bitmap bitmap = mChartView.toBitmap();
                        try {
                          File file = new File(Environment.getExternalStorageDirectory(), "test" + index++ + ".png");
                          FileOutputStream output = new FileOutputStream(file);
                          bitmap.compress(CompressFormat.PNG, 100, output);
                        } catch (Exception e) {
                          e.printStackTrace();
                        }
                      }
                    });
                    //END CHART ADDITIONS

FULL STACK TRACE (When i give layout containing chart a defined height of 100dp)

11-14 20:28:13.430: E/AndroidRuntime(26620): java.lang.NullPointerException
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.graphics.Canvas.throwIfRecycled(Canvas.java:954)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.graphics.Canvas.drawBitmap(Canvas.java:980)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at org.achartengine.GraphicalView.onDraw(GraphicalView.java:174)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.View.draw(View.java:6880)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.View.draw(View.java:6986)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.widget.ScrollView.draw(ScrollView.java:1409)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.View.draw(View.java:6883)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.View.draw(View.java:6883)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2116)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewRoot.draw(ViewRoot.java:1565)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewRoot.performTraversals(ViewRoot.java:1301)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1914)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.os.Looper.loop(Looper.java:130)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at android.app.ActivityThread.main(ActivityThread.java:3859)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at java.lang.reflect.Method.invokeNative(Native Method)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at java.lang.reflect.Method.invoke(Method.java:507)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-14 20:28:13.430: E/AndroidRuntime(26620):    at dalvik.system.NativeStart.main(Native Method)
  • 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-14T12:53:04+00:00Added an answer on June 14, 2026 at 12:53 pm

    I encountered a similar issue before. trying to use the zoom for achartengine is impossible inside a dialog. try commenting out setzoomvisible and it should work for you.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.