Java Question java.lang.NoClassDefFoundError

walterf25

Expert
Licensed User
Longtime User
Hello all, i'm trying to create a library for this API here.
The xml and jar files compile fine in eclipse, but when i use it in B4A i get this error below...
java.lang.NoClassDefFoundError: com.genesis.hapi.hapipay
at com.genesis.mobilerep.main._activity_create(main.java:318)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at com.genesis.mobilerep.main.afterFirstLayout(main.java:98)
at com.genesis.mobilerep.main.access$100(main.java:16)
at com.genesis.mobilerep.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5299)
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:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)

I have been searching in the forums and google the whole day, and i've done about everything advised in all the posts i've found, including using JDK1.6.

from what i can understand in the error, it can't find the class named hapipay, which is the class in the library i created, i'm not an expert in Java obviously but this doesn't make sense.

Below is the code i have for the library, and i'm also attaching the project with the files needed.

B4X:
package com.genesis.hapi;

import java.util.List;

import android.content.Context;
import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.DontInheritEvents;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

import com.handpoint.api.Device;
import com.handpoint.api.Events;
import com.handpoint.api.Hapi;
import com.handpoint.api.HapiFactory;
import com.handpoint.api.SignatureRequest;
import com.handpoint.api.TransactionResult;

@ShortName("HapiPayment")
@Permissions(values={"android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN", "android.permission.INTERNET"})
@Author("Walter")
@Version(1.1f)
@ActivityObject
@DontInheritEvents
@DependsOn(values={"hapi-android-3.1.1"})

public class hapipay extends AbsObjectWrapper<Hapi> implements Events.Required{
   
    private Hapi api;

    public void Initialize(BA ba){
        BA.Log("estamos inicializando");
        Initapi(ba.context.getApplicationContext());
        setObject(api);
    }
   
    public void Initapi(Context context){
        BA.Log("Inicializando");
       
        String SharedSecret = "0102030405060708091011121314151617181920212223242526272829303132";       
        this.api = HapiFactory.getAsyncInterface(this, context).defaultSharedSecret(SharedSecret);
    }

    @Override
    public void deviceDiscoveryFinished(List<Device> arg0) {
        // TODO Auto-generated method stub
       
    }

I hope i can get an answer to this issue.

thanks,
Walter
 

Attachments

  • HapiPay.zip
    4.4 KB · Views: 245
  • hapi-android-3.1.1.jar
    121.4 KB · Views: 260

walterf25

Expert
Licensed User
Longtime User
There is no class named com.genesis.hapi.hapipay in the jar file (open it with 7zip to see).
Hi Erel the jar file i included in the post above is the jar file i'm trying to wrap, the "com.genesis.hapi.hapipay" class is the name of the class in the file i created. see attached.

Thanks,
Walter
 

Attachments

  • HapiPay.jar
    2.2 KB · Views: 278

warwound

Expert
Licensed User
Longtime User
You said you've tried JDK 1.6 but are you sure that (in Eclipse) the project is being compiled with 1.6?

Take a look at this post of mine: http://www.b4x.com/android/forum/th...ssdeffounderror-on-library.39015/#post-231207
It's not the version of the SDK you have installed that matters but the 'java compliance level' which Eclipse uses to compile the project.
Android is not compatible with 1.7 compliance level and a ClassNotFoundException is a common symptom of a library not compiled with complianc level 1.6.

Martin.
 

walterf25

Expert
Licensed User
Longtime User
You said you've tried JDK 1.6 but are you sure that (in Eclipse) the project is being compiled with 1.6?

Take a look at this post of mine: http://www.b4x.com/android/forum/th...ssdeffounderror-on-library.39015/#post-231207
It's not the version of the SDK you have installed that matters but the 'java compliance level' which Eclipse uses to compile the project.
Android is not compatible with 1.7 compliance level and a ClassNotFoundException is a common symptom of a library not compiled with complianc level 1.6.

Martin.
Hi Martin, yes i made sure that the compliance level is also 1.6, but i still get the same error, it just doesn't make any sense to me, the class that is not found according to the error is the name of the class i created for the library.
 

walterf25

Expert
Licensed User
Longtime User
This is why I pointed him to SLC ;)
I get this error with SLC Erel
Starting step: Compiling Java code.
javac 1.7.0_51
C:\Users\Walter\workspace\HapiPay\src\com\genesis\hapi\hapipay.java:16: error: package com.handpoint.api does not exist
import com.handpoint.api.Device;
^
1 error


Error.
 

walterf25

Expert
Licensed User
Longtime User

warwound

Expert
Licensed User
Longtime User
Ok now it compiles and creates the xml and jar files, i can see the library under the libs tab, but when i try to declare a variable as the name of the shortname nothing comes up, why is that?

Did you right click and refresh the b4a ide libs panel?

Martin.
 

walterf25

Expert
Licensed User
Longtime User

Attachments

  • hapi-android-3.1.1.zip
    115.9 KB · Views: 245

Erel

B4X founder
Staff member
Licensed User
Longtime User
It does show here:
SS-2014-04-19_15.22.31.png
 

walterf25

Expert
Licensed User
Longtime User
It does show here:
SS-2014-04-19_15.22.31.png
Exactly that's what is so confusing because it shows up but yet it gives me that error posted above.

Do you have any clues as to why this might be?
 
Top