Java Question Error creating a library

aviario

Active Member
Licensed User
Longtime User
Hello.

First of all sorry for my bad english.
Second. I haven't idea of Java, but I'm searching documentation on google and forums.

I'm trying to create a library in eclipse to print image on esc /p printers. I found code to do this in java, and I used Eclipse to generate jar and javadoc.

I import the jar into b4a, and i can access to procedures of the library. But When I run b4a code i have the next error:

PackageAdded: package:b4a.example
main_globals (java line: 273)
java.lang.NoClassDefFoundError: sico.PosPrinter.PosPrinterClass
at b4a.example.main._globals(main.java:273)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.example.main.initializeGlobals(main.java:230)
at b4a.example.main.afterFirstLayout(main.java:86)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)

I read a lot in google, but i don't undestand.

Here are the library.

In the zip isn't android.jar, B4AShared.jar and Core.jar, that i have in a libs folder inside Posprinter folder, because the forun don't let me upload files up to 512kb.

Can you help me?

Thanks.
 

Attachments

  • PosPrinter.zip
    15.3 KB · Views: 205

socialnetis

Active Member
Licensed User
Longtime User
I have seen 2 ways of getting a NoClassDefFoundError:
- When wrapping a java library, you need to add the "@DependsOn" notation, an put the name of the library you are wrapping. Which I assume is not the case, because there are not imports to any external library related to a printer in the code you provided
- Compiling in eclipse using JDK 1.7, you need to use 1.6
 

aviario

Active Member
Licensed User
Longtime User
Hello. Tranks for reply.
I created jar with eclipse, with the option to export.
first I compiling using JDK 1.7. But I read in foruns that I need to use 1.6. Then I change in Java Paths, Jdk 1.7 for 1.6 but Isn't work.
the only libraries that i use are android.jar, B4AShared.jar and Core.jar, and of course Jdk 1.6

I read something abaout classpath, but I don't undestand it. I try to add android.jar, B4AShared.jar and Core.jar into jar created, into a folder named libs. But isn't work.

When I add library to b4a is ok, but when compiling project crash.

Thanks again for you replies.
 

aviario

Active Member
Licensed User
Longtime User
Thanks for reply.

I use SLC Tool and solve the error java.lang.NoClassDefFoundError: sico.PosPrinter.PosPrinterClass

Now I have the next error

java.lang.NullPointerException
at android.widget.Toast.<init>(Toast.java:92)
at android.widget.Toast.makeText(Toast.java:233)
at sico.PosPrinter.PosPrinterClass.print_image(PosPrinterClass.java:74)
at b4a.example.main._activity_create(main.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.example.main.afterFirstLayout(main.java:89)
at b4a.example.main.access$100(main.java:16)
at b4a.example.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

I supose the error occurs because I Inicialize some var as null and i can't do it. Meaby the error is in toast line.

I use Toast.makeText(mContexto, "Fichero no Existe", Toast.LENGTH_SHORT)
because I can't do it Toast.makeText(this, "Fichero no Existe", Toast.LENGTH_SHORT), because i haven't activity.

Then I create a mContext as Activity an inicialized to null:

import android.widget.Toast;
import android.app.Activity;

Activity mContexto = null;
......
Toast.makeText(mContexto, "Fichero no Existe", Toast.LENGTH_SHORT)

but I don't konw if this is ok.

Thansk again
 
Top