我正在.xls
使用以下代码创建一个文件。我从http://www.vogella.de/articles/JavaExcel/article.html和 http://www.andykhan.com/jexcelapi/tutorial.html得到了参考请建议解决方案或替代方法。
下面是代码
String filename = "SpreadsheetTest.xls";
File root = Environment.getExternalStorageDirectory();
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(new File(root, filename), wbSettings);
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
Label label = new Label(0, 2, "A label record");
sheet.addCell(label);
Number number = new Number(3, 4, 3.1459);
sheet.addCell(number);
workbook.write();
workbook.close();
上面的代码给出NullPointerException
:
08-19 14:34:46.354: ERROR/AndroidRuntime(3298): Uncaught handler: thread main exiting due to uncaught exception
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spreadsheet/com.spreadsheet.MainScreen}: java.lang.NullPointerException
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at android.os.Looper.loop(Looper.java:123)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at android.app.ActivityThread.main(ActivityThread.java:4363)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at java.lang.reflect.Method.invoke(Method.java:521)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at dalvik.system.NativeStart.main(Native Method)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): Caused by: java.lang.NullPointerException
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at jxl.biff.StringHelper.getUnicodeBytes(StringHelper.java:141)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at jxl.biff.FontRecord.getData(FontRecord.java:289)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at jxl.biff.WritableRecordData.getBytes(WritableRecordData.java:71)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at jxl.write.biff.File.write(File.java:147)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at jxl.biff.Fonts.write(Fonts.java:110)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at jxl.write.biff.WritableWorkbookImpl.write(WritableWorkbookImpl.java:821)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at com.spreadsheet.MainScreen.onCreate(MainScreen.java:59)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
08-19 14:34:46.362: ERROR/AndroidRuntime(3298): ... 11 more
请指导我解决这个问题。如果有的话,请向我建议任何生成 xls 文件的替代方法。