2012-12-03 17 views
0

电子邮件适用于小型图表,但大型图表无法导出并出现空指针异常。
情况下,电子邮件:出口在Android中导出图表时出现空指针

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")); 
} 

这里

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(); 
        } 
       }); 
      } 

代码是logcat的

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得到一个空指针异常()方法。我怀疑可能是图表太大,因为代码可以完美地与其他小图表一起工作,任何人都知道如何去做它?

+0

Logcat会很好;) – Siggy

+0

@Siggy我把logcat –

回答

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")); 
    } 
相关问题