电子邮件适用于小图表,但大图表无法导出并给出空指针异常。
案例邮箱:
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() 方法上遇到空指针异常。我怀疑可能是图表太大了,因为代码可以完美地与其他小图表一起使用,任何人都知道如何去做?