NoClassDefFoundError的插入使用Apache POI和放大器在Android应用映像时; MS Excel中 [英] NoClassDefFoundError when inserting image in Android app using Apache poi & MS Excel

查看:343
本文介绍了NoClassDefFoundError的插入使用Apache POI和放大器在Android应用映像时; MS Excel中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Apache POI插入一个PNG图像到我的Excel工作表。

I want to insert a PNG image into my Excel sheet using Apache poi.

要做到这一点我用这个code:

To do that I use this code:

//add picture data to this workbook.
InputStream is = new FileInputStream("/sdcard/MYAPPFOLDER/logo_app.png");
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();

CreationHelper helper = workbook.getCreationHelper();

// Create the drawing patriarch.  This is the top level container for all shapes. 
Drawing drawing = sheet.createDrawingPatriarch();

//add a picture shape
ClientAnchor anchor = helper.createClientAnchor();
//set top-left corner of the picture,
//subsequent call of Picture#resize() will operate relative to it
anchor.setCol1(0);
anchor.setRow1(0);
Picture pict = drawing.createPicture(anchor, pictureIdx);

//auto-size picture relative to its top-left corner
pict.resize();

但在我第一次,我已经加入这个库 commons- codeC-1.8.jar ,现在我有这个错误解决的一个错误:

But in first time I have one error which I have solved by adding this library commons-codec-1.8.jar and now I have this error:

02-21 10:10:51.466: E/AndroidRuntime(31691): FATAL EXCEPTION: main
02-21 10:10:51.466: E/AndroidRuntime(31691): java.lang.NoClassDefFoundError: java.awt.Dimension
02-21 10:10:51.466: E/AndroidRuntime(31691):    at org.apache.poi.ss.util.ImageUtils.getImageDimension(ImageUtils.java:52)
02-21 10:10:51.466: E/AndroidRuntime(31691):    at org.apache.poi.hssf.usermodel.HSSFPicture.getImageDimension(HSSFPicture.java:243)
02-21 10:10:51.466: E/AndroidRuntime(31691):    at org.apache.poi.hssf.usermodel.HSSFPicture.getPreferredSize(HSSFPicture.java:163)

指向这一行:

pict.resize();

我怎样才能解决这个问题?

How can I fix it?

推荐答案

您不能使用涉及图形程序( java.awt中)的纯Java库,由于Android没有实施它们,因为它使用它自己的图形库。底线是,你不能使用你想要的Andr​​oid库中,虽然我敢肯定有其他方法可以做到你想做的事。

You can't use pure Java libraries that involve graphics routines (java.awt), because Android hasn't implemented them, as it uses it's own graphics library. Bottom line is, you can't use the library you want with Android, although I'm sure there's other ways to do the task you want to do.

Android使用了几个基本类型,即查看 S,画布可绘制秒。看看这些,看看他们是否满足您的需求。

Android uses a few base types, namely Views, Canvas, and Drawables. Take a look at those, and see if they meet your needs.

这篇关于NoClassDefFoundError的插入使用Apache POI和放大器在Android应用映像时; MS Excel中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆