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:


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:


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: 382

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!

Managed to create a working .xls document!
 
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
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…