Java Question Compile to Library - cannot find symbol

MarcoRome

Expert
Licensed User
Longtime User
When I compile the program in a library I have this error.
If I try the code from the main activity it all works

B4X:
B4A version: 7.01
Parsing code.    (0.00s)
Compiling code.    (0.01s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
Generating R file.    (0.03s)
Compiling generated Java code.    Error
javac 1.8.0_92
src\b4a\example\pdftotext.java:123: error: cannot find symbol
            if(processBA.subExists(EventName.toLowerCase(BA.cul) + "_finish")){
               ^
  symbol:   variable processBA
  location: class pdftotext
Note: src\b4a\example\starter.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

I have this code in main:
B4X:
#Region Module Attributes
    #CanInstallToExternalStorage: False
    #LibraryAuthor: Devil-App
    #LibraryName: XXXX
    #LibraryVersion: 1.00
#End Region

#AdditionalJar: xxxxx-5.5.6

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
 

End Sub

This code in Class:
B4X:
Sub Class_Globals
    Dim nativeMe As JavaObject
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(namefilexx As String, namefileyy As String, evento As String)
    Log(File.DirAssets)
    Log(File.DirRootExternal)
    Dim nome_evento As String = evento
    nativeMe.InitializeContext
    Dim filepdf As String = namefilexx
    Dim filetxt As String = namefileyy
    nativeMe.RunMethod("funct", Array(filepdf, filetxt, nome_evento))
End Sub



#If Java

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy;
import com.itextpdf.text.pdf.parser.TextExtractionStrategy;

.......
            out.flush();
            out.close();
            String Convertito = "Done";
            if(processBA.subExists(EventName.toLowerCase(BA.cul) + "_finish")){
                BA.Log("Found");
                processBA.raiseEventFromUI(this, EventName.toLowerCase(BA.cul) + "_finish", Convertito);
            } else {
                BA.Log("Not Found");
            }
    }

#End If

Where i wrong ?
Thanks
Marco
 

MarcoRome

Expert
Licensed User
Longtime User
Here all project in attachment ( i solved creating a wrapper, but i would like to understand where's the error )
The jar file is HERE
Thanks Erel
 

Attachments

  • PdtToTxt2.zip
    35.2 KB · Views: 273

MarcoRome

Expert
Licensed User
Longtime User
Yes right, resolved in this way:
B4X:
....
try {
            BA ba = (BA) this.getClass().getField("processBA").get(null);
            if(ba.subExists(EventName.toLowerCase(BA.cul) + "_onmessage")){
                BA.Log("Found");
                ba.raiseEventFromUI(this, EventName.toLowerCase(BA.cul) + "_onmessage", Convertito);
            } else {
                BA.Log("Not Found");
            }
            } catch (Exception e) {
throw new RuntimeException(e);
}
......
 

MarcoRome

Expert
Licensed User
Longtime User
Yes right, resolved in this way:
B4X:
....
try {
            BA ba = (BA) this.getClass().getField("processBA").get(null);
            if(ba.subExists(EventName.toLowerCase(BA.cul) + "_onmessage")){
                BA.Log("Found");
                ba.raiseEventFromUI(this, EventName.toLowerCase(BA.cul) + "_onmessage", Convertito);
            } else {
                BA.Log("Not Found");
            }
            } catch (Exception e) {
throw new RuntimeException(e);
}
......

The problem persists. I have open new thread HERE
 
Top