0

电子邮件适用于小图表,但大图表无法导出并给出空指针异常。
案例邮箱:

try {

  new LoadAllData().execute();
  pDialog.setMessage("Please wait..");

             doExport();

            } catch (IOException e) {
                e.printStackTrace();

                dialog = new Dialog(testActivity.this);
                dialog.setContentView(R.layout.description);
                dialog.show();
                dialog.setTitle("Access Denied!");
                description = (TextView) dialog.findViewById(R.id.descriptionText);
                description.setText("Cannot export Chart: " +    e.getMessage());
                description.setTextColor(0xFFFFFFFF);
                okButton = (Button) dialog.findViewById(R.id.okButton);
                okButton.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.cancel();
                    }
                });
            }

出口代码

  private void doExport() throws IOException {
    final Intent sendIntent = new Intent(Intent.ACTION_SEND);
    final Image image = chart.getExport().getImage()
            .image(chart.getWidth(), chart.getHeight());

    File file;
    final FileOutputStream stream;

    file = new File("/sdcard/test.png");
    stream = new FileOutputStream(file);

    image.save(stream);
    stream.flush();
    stream.close();

    sendIntent.setType("image/png");
    sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///sdcard/test.png"));

    startActivity(Intent.createChooser(sendIntent, "Export"));
}

这是日志猫

  12-03 13:59:32.174: E/AndroidRuntime(11871): java.lang.NullPointerException
  12-03 13:59:32.174: E/AndroidRuntime(11871): at    com.sympo.test.android.testActivity.doExport(testActivity.java:8261)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at com.sympo.test.android.testActivity.MenuItemSelectedEvent(testActivity.java:8215)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at com.sympo.test.android.CustomMenuListener$1.onClick(CustomMenuListener.java:166)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at android.view.View.performClick(View.java:4101)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at android.view.View$PerformClick.run(View.java:17078)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at android.os.Handler.handleCallback(Handler.java:615)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at android.os.Handler.dispatchMessage(Handler.java:92)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at android.os.Looper.loop(Looper.java:155)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at android.app.ActivityThread.main(ActivityThread.java:5485)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at java.lang.reflect.Method.invokeNative(Native Method)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at java.lang.reflect.Method.invoke(Method.java:511)
 12-03 13:59:32.174: E/AndroidRuntime(11871):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)

我在 doExport() 方法上遇到空指针异常。我怀疑可能是图表太大了,因为代码可以完美地与其他小图表一起使用,任何人都知道如何去做?

4

1 回答 1

0

我通过导出包含我想通过电子邮件发送的内容的整个布局来解决它。请注意,您可以通过电子邮件发送您希望的任何布局...享受!!!!

 private void doExport() throws IOException {


RelativeLayout rl =(RelativeLayout)findViewById(R.id.testlayout);
    Bitmap b = Bitmap.createBitmap(rl.getWidth(), rl.getHeight(),Bitmap.Config.ARGB_8888);

    int weight,height;

    weight =  rl.getWidth();

    height =  rl.getHeight();

    Bitmap cs = Bitmap.createBitmap(weight, height, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(cs);

 c.drawBitmap(b,0,0,null);

  rl.draw(c); 

  File file1 = new File("/sdcard/test.png");
   FileOutputStream fos = new FileOutputStream(file1);



  if (fos != null) {

         cs.compress(Bitmap.CompressFormat.PNG, 90, fos);

       fos.close();
   }
 Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
 picMessageIntent.setType("message/rfc822");

 picMessageIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///sdcard/test.png"));

        startActivity(Intent.createChooser(picMessageIntent, "Export"));
   }
于 2012-12-13T14:27:51.027 回答