I know this question was asked earlier once but I see no answer to it from back then. Hence if you someone can guide me in this regard, I would grateful.

Android need help with diagram

I have an error in the below part:

        double x = 0;
    double y = 0;


    for (int i=0;i<10;i++)
    {
        x=x+10;
        y=y+5;
        mCurrentSeries.add(x, y);
    }

    Log.i("Series Count",""+mCurrentSeries.getItemCount());


    for (int xy=0;xy<10;xy++)
    {
    Log.i("Series -- Values","["+mCurrentSeries.getX(xy)+","+mCurrentSeries.getY(xy)+"]");
    }

    if (mChartView != null) {
        mChartView.repaint();
    }

    Bitmap bitmap = mChartView.toBitmap();

    try {
        File file = new File(Environment.getExternalStorageDirectory(),
                "test" + index++ + ".png");
        OutputStream output = new FileOutputStream(file);
        bitmap.compress(CompressFormat.PNG, 100, output);   

        output.flush();
        output.close(); 
    } catch (Exception e) {
        Toast.makeText(LineChartTestActivity.this, "Graph Exception", Toast.LENGTH_LONG).show();//Added Toast to see exception on device
        Log.e("ERROR", "BITMAP EXCEPTION");
        e.printStackTrace();

    }

To be specific the below line gives me a java.lang.NullPointerException

bitmap.compress(CompressFormat.PNG, 100, output);

Like Handy mentioned in his question, I'm also able to make it work using the editText but for some odd reason it will not work when I give explicit values from the code!

Please advise.

有帮助吗?

解决方案

There used to be an opened issue for this. Please see the comments here, maybe it will help you get the bitmap saved.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top