Java Question 2 classes referencing

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hello,

I'm making my next library that for sure will be really helpful to a lot of people.I will try to explain.

I have 2 classes in (one) library where you can reference too. (with shortname)

B4X:
   Dim EW As ExcelWorker
   Dim Sheet1 As ExcelSheets

From EW, I need to create a sheet that refers to ExcelSheets.

B4X:
Sheet1.sheet = EW.newSheet("Sheet1")

This is my java code from Worker1:
B4X:
public Sheet newSheet(String SheetName) {
          Sheet sheet = wb.createSheet(SheetName);
          return sheet;
       }

Page is loaded from a java archive (jar) file in my library.

But everytime i try to run it, i get the following error:

Compiling code. 0.01
Generating R file. 0.00
Compiling generated Java code. Error
B4A line: 22
Sheet1.sheet = EW.newSheet(\
javac 1.6.0_21
src\com\rootsoft\worker\main.java:217: cannot access org.apache.poi.ss.usermodel.Sheet
class file for org.apache.poi.ss.usermodel.Sheet not found
mostCurrent._sheet1.sheet = mostCurrent._ew.newSheet("Sheet1");
^
1 error

I tried a lot of possibilities. The main reason for this is that I want to declare more than one sheets when creating one and so I can reference to others.

Dim sheet1, sheet2 as ExcelSheets
and so sheet1 acts different than sheet2

I think AlwaysBusy uses this a lot in his apps like when he has ABWifiObject, etc. But I think there he gets the info from other classes where I get them from a jar file
Hope you can help me.

Tomas
 

stevel05

Expert
Licensed User
Longtime User
Hi,

Looking at the documentation here which I'm sure you have, it looks like Sheet is an interface rather than a class.

I'm no java expert, but that may be your problem. It lists the implementing classes.

Hope it helps.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hello Erel,

Sorry for the late response.
I couldn't come online because of my exams started now.

So, now I stumbled on another problem., and I first would have to fix this i guess.

I receive the following error in my log file:

Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.rootsoft.officeworker cmp=com.rootsoft.officeworker/.main } from pid 13936
Start proc com.rootsoft.officeworker for activity com.rootsoft.officeworker/.main: pid=13989 uid=10003 gids={1015}
1
Could not find class 'org.apache.poi.hssf.usermodel.HSSFWorkbook', referenced from method com.rootsoft.excelworker.ExcelWorker.newWorkbook
VFY: unable to resolve new-instance 387 (Lorg/apache/poi/hssf/usermodel/HSSFWorkbook;) in Lcom/rootsoft/excelworker/ExcelWorker;
VFY: replacing opcode 0x22 at 0x0000
VFY: dead code 0x0002-0005 in Lcom/rootsoft/excelworker/ExcelWorker;.newWorkbook ()V
2
2
** Activity (main) Create, isFirst = true **
3
ExcelWorker has been initialized.
4
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x2aac8578)
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: org.apache.poi.hssf.usermodel.HSSFWorkbook
at com.rootsoft.excelworker.ExcelWorker.newWorkbook(ExcelWorker.java:39)
at com.rootsoft.officeworker.main._activity_create(main.java:219)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at com.rootsoft.officeworker.main.afterFirstLayout(main.java:84)
at com.rootsoft.officeworker.main.access$100(main.java:16)
at com.rootsoft.officeworker.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity com.rootsoft.officeworker/.main
Pub com.google.android.maps.LocalSuggestionProvider: com.google.googlenav.provider.LocalSuggestionProvider
Pub com.google.android.maps.NavigationAvailabilityProvider: com.google.googlenav.provider.NavigationAvailabilityProvider
Start proc mobi.infolife.uninstaller for broadcast mobi.infolife.uninstaller/mobi.infolife.common.app.AppMonitorBroadcastReceiver: pid=13996 uid=10139 gids={3003, 1007}
No longer want com.svox.pico (pid 13666): hidden #16
Start proc cn.opda.android.optimize_lite for broadcast

So I downloaded the Apache POI 3.7 stable version to work with and in my build path referenced to ALL libraries including in there. (i first tried with only POI3.7.jar, but I got the same error.)

This is the code I run:
B4X:
/**
    * creates a new workbook.
    */
   public void newWorkbook() {
      Workbook wb = new HSSFWorkbook(); 
   }

and these is my B4A code:

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Log("1")
   Dim EW As ExcelWorker
   Dim Sheet As ExcelSheets
   Log("2")
   'Dim Sheet1 As ExcelSheets
   Log("2")

End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
   Log("3")
      EW.Initialize("WordWorker")
   End If
   Log("4")
   EW.newWorkbook
Log("5")

End Sub

I hope you can help me as this could be a very useful library.

Tomas
 

Attachments

  • OfficeWorkerAlpha.zip
    2.4 KB · Views: 279

XverhelstX

Well-Known Member
Licensed User
Longtime User
Ok, I seem to get it working of my second issue.
i did it the way like admob. (copy existing jar file op poi, and rename a copy of admob to poi.xml).
However, what should I check if I want to get it in 1 jar file? (everything?) or should I keep it this way?

Thanks a lot again!

Tomas

EDIT: HELL YEAH! :D

Managed to create a working .xls document! :D
 
Last edited:

XverhelstX

Well-Known Member
Licensed User
Longtime User
Thanks Erel.

Still one more question.
I keep having a nullpointerexception here:

B4X:
Row1.createRow(Sheet1.sheet,0)

B4X:
public Row row;
   
   /**
    * Creates a row
    */
   public void createRow(Sheet sheet, int index) {
      row = sheet.createRow(index);
   }

B4X:
If FirstTime Then
      EW.Initialize("WordWorker")
   End If
   EW.createHSSFWorkbook(wb.workbook)
   wb.initialize
   Wb.createSheet(Sheet1.sheet,"Calender")

   Row1.createRow(Sheet1.sheet,0)

I don't know how i could declare a Row without being it null.
but createSheet on workbook works fine:

B4X:
public void createSheet(Sheet sheet, String sheetName) {
      sheet = workbook.createSheet(sheetName);
   }


Tomas
 
Top