Java Question java.lang.NoClassDefFoundError - need help

Semendey

Member
Hello everyone.

I'm trying to wrap the library.

Here is the wrapper code

wrapper:
public  class MyLipPhone  {       
    private BA ba;
    private String event;
    Context ctx = null;
    public static MyLipPhone mInstance;
    public LinphoneCore mLinphoneCore;
    public static Context mContext;

        public void initialize(BA ba, String event) {   
        this.ba = ba;
        this.event = event;
        mContext = ba.context;
        BA.Log("1");
        LinphoneMiniManager mLinphoneManager = new LinphoneMiniManager(mContext);
        BA.Log("2");
        mLinphoneCore = mLinphoneManager.getLc();
        mInstance = this;
        //setObject((LinphoneCore) mLinphoneManager);       
    }


  class LinphoneMiniManager implements LinphoneCoreListener {

   //class LinphoneMiniManager  {           
            public LinphoneMiniManager mInstance;
            public Context mContext;
            public LinphoneCore mCore;
            public LinphoneCoreFactory mFactory;
            //public static LinphonePreferences mPrefs;
            public Timer mTimer;
            public SurfaceView mCaptureView;
            //public CallbackContext mCallbackContext;
            //public CallbackContext mLoginCallbackContext;
    
            
            public LinphoneMiniManager(Context c) {
                BA.Log("2");
                mContext = c;
            
                LinphoneCoreFactory.instance().setDebugMode(true, "Linphone Mini");
                //mPrefs = LinphonePreferences.instance();

                BA.Log("3");
                ////////////////////////////////////////////////////////////////////////////////////////
                BA.Log("mCore");
                try {
                    mCore = LinphoneCoreFactory.instance().createLinphoneCore((LinphoneCoreListener) mInstance, mContext);
                } catch (LinphoneCoreException e) {
                    // TODO Автоматически созданный блок catch
                    e.printStackTrace();
                }
                        
                BA.Log("mCore 2");       
                        
                        
                //mCore = LinphoneCoreFactory.instance().createLinphoneCore(this, basePath + "/.linphonerc", basePath + "/linphonerc", null, mContext);
                

                

/*
                setUserAgent();
                //setFrontCamAsDefault();
                startIterate();
                mInstance = this;
                mCore.setNetworkReachable(true); // Let's assume it's true

                mCore.addListener((LinphoneCoreListener)mContext);
                mCaptureView = new SurfaceView(mContext);
                
                
                
                
                
                            mCore.setContext(mContext);


                            int availableCores = Runtime.getRuntime().availableProcessors();
                            BA.Log("MediaStreamer : " + availableCores + " cores detected and configured");
                            mCore.setCpuCount(availableCores);

                            int migrationResult = getLc().migrateToMultiTransport();
                            BA.Log( "Migration to multi transport result = " + migrationResult);

                            mCore.setNetworkReachable(true);

                            // echo cancellation
                            boolean isEchoCancellation =  true;
                            mCore.enableEchoCancellation(isEchoCancellation);

                            // adaptive rate control
                            boolean isAdaptiveRateControl = true;
                            mCore.enableAdaptiveRateControl(isAdaptiveRateControl);

                            // audio bit rate setting
                            //LinphoneUtils.getConfig(mServiceContext).setInt("audio", "codec_bitrate_limit", 128);

                            mCore.setPreferredVideoSizeByName("720p");
                            mCore.setUploadBandwidth(1536);
                            mCore.setDownloadBandwidth(1536);

                            mCore.setVideoPolicy(mCore.getVideoAutoInitiatePolicy(), true);
                            mCore.setVideoPolicy(true, mCore.getVideoAutoAcceptPolicy());
                            mCore.enableVideo(true, true);

                            setCodecMime();
        */                   
            }
            
            public LinphoneCore getLc(){
                return mCore;
            }
            
            private void copyAssetsFromPackage(String basePath) throws IOException {
                String package_name = mContext.getPackageName();
                Resources resources = mContext.getResources();

                //copyIfNotExist(mContext, resources.getIdentifier("oldphone_mono", "raw", package_name), basePath + "/oldphone_mono.wav");
                //copyIfNotExist(mContext, resources.getIdentifier("ringback", "raw", package_name), basePath + "/ringback.wav");
                //copyIfNotExist(mContext, resources.getIdentifier("toy_mono", "raw", package_name), basePath + "/toy_mono.wav");
                copyIfNotExist(mContext, resources.getIdentifier("linphonerc_default", "raw", package_name), basePath + "/.linphonerc");
                copyFromPackage(mContext, resources.getIdentifier("linphonerc_factory", "raw", package_name), new File(basePath + "/linphonerc").getName());
                copyIfNotExist(mContext, resources.getIdentifier("lpconfig", "raw", package_name), basePath + "/lpconfig.xsd");
                //copyIfNotExist(mContext, resources.getIdentifier("rootca", "raw", package_name), basePath + "/rootca.pem");
                //copyIfNotExist(mContext, resources.getIdentifier("vcard_grammar", "raw", package_name), basePath + "/vcard_grammar.pem");
                //copyIfNotExist(mContext, resources.getIdentifier("cpim_grammar", "raw", package_name), basePath + "/cpim_grammar.pem");
            }
            
            public void copyIfNotExist(Context context, int ressourceId, String target) throws IOException {
                File lFileToCopy = new File(target);
                if (!lFileToCopy.exists()) {
                    copyFromPackage(context, ressourceId, lFileToCopy.getName());
                }
            }

            public void copyFromPackage(Context context, int ressourceId, String target) throws IOException {
                FileOutputStream lOutputStream = context.openFileOutput (target, 0);
                InputStream lInputStream = context.getResources().openRawResource(ressourceId);
                int readByte;
                byte[] buff = new byte[8048];
                while (( readByte = lInputStream.read(buff)) != -1) {
                    lOutputStream.write(buff,0, readByte);
                }
                lOutputStream.flush();
                lOutputStream.close();
                lInputStream.close();
            }
            
            private void setUserAgent() {
                try {
                    String versionName = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName;
                    if (versionName == null) {
                        versionName = String.valueOf(mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode);
                    }
                    mCore.setUserAgent("LinphoneMiniAndroid", versionName);
                } catch (NameNotFoundException e) {
                }
            }
            
            private void startIterate() {
                TimerTask lTask = new TimerTask() {
                    @Override
                    public void run() {
                        mCore.iterate();
                    }
                };

                mTimer = new Timer("LinphoneMini scheduler");
                mTimer.schedule(lTask, 0, 20);
            }
            
            

            private void setCodecMime()
            {
                for (final PayloadType pt : mCore.getVideoCodecs())
                {
                    BA.Log("setCodecMime = " + pt.getMime());
                    if (!pt.getMime().equals("VP8"))
                    {
                        try
                        {
                            BA.Log("disable codec " + pt.getMime());
                            mCore.enablePayloadType(pt, false);
                        }
                        catch (LinphoneCoreException e)
                        {
                            BA.Log(e.toString() );
                        }
                    }
                }
            }

    
            
        
}




}

The wrapper compiles fine, but when I use it in an application I get an error:

main$ResumableSub_Activity_Createresume (java line: 398)
java.lang.NoClassDefFoundError: mylip.MyLipPhone$LinphoneMiniManager
at mylip.MyLipPhone.initialize(MyLipPhone.java:81)
at b4a.example.main$ResumableSub_Activity_Create.resume(main.java:398)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

I am not a strong programmer, so I ask for your tips
 

Semendey

Member
Thank you

@DependsOn(values = { "linphone-sdk" })
There is such a declaration in the wrapper code,
and the linphone-sdk.jar file itself is placed in the additional libraries folder
 

Semendey

Member
Here are the project files, maybe it will help
 

Attachments

  • MyLipPhone.java
    18.2 KB · Views: 25
  • linphone-sdk.jar
    281.6 KB · Views: 22

drgottjr

Expert
Licensed User
Longtime User
i vote for moving the entire LinphoneMiniManager class outside your main MyLipPhone class. you have it as an inner class. it has to be instantiated differently. just put it as is on the other side of MyLipPhone's closing brace.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Better to declare the inner class as public static:
B4X:
public static class LinphoneMiniManager implements LinphoneCoreListener

However I don't think that this is the cause of this issue.
@DependsOn(values = { "linphone-sdk" })
There is such a declaration in the wrapper code,
Post the full class code. I don't see it in your code. You can also check the generated XML file and make sure that it is there.
 

Semendey

Member
Better to declare the inner class as public static:
B4X:
public static class LinphoneMiniManager implements LinphoneCoreListener

However I don't think that this is the cause of this issue.

Post the full class code. I don't see it in your code. You can also check the generated XML file and make sure that it is there.

Thank you.

I fixed this error miraculously by changing the file name from linphone-SDK to linphone

Now I'm working on a new error:

java.lang.ClassCastException: androidx.multidex.MultiDexApplication cannot be cast to org.linphone.core.LinphoneCoreListener
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
Thank you.

I fixed this error miraculously by changing the file name from linphone-SDK to linphone

Now I'm working on a new error:

java.lang.ClassCastException: androidx.multidex.MultiDexApplication cannot be cast to org.linphone.core.LinphoneCoreListener

We are both not native English speakers, but I always use my "bad" English or Google translate. Here are my thoughts on your source code:
Especially as a beginner, it is useful to put the source code in the free Eclipse. I have created a Java project with your source code. Eclipse examines your source code and immediately reports that there are 10 unused imports (if you remove them, the jar file becomes smaller).

My SLC comes up with all kinds of errors about Russian characters (unmappable character for encoding Cp1252) which prevents the xml help file from being created. I ignore them because SLC reports:

Starting step: Compiling Java code.
Completed successfully.
Starting step: Creating jar file.
Completed successfully.
Starting step: Creating XML file.
D:\Data\EclipseWorkspace\A TTS2\Eclipse\M3SIP\src\microdrie\m3sip\MyPJSIP.java:79: error: unmappable character for encoding Cp1252 <=== I ignore those errors


My Eclipse setup is as follows:

1744718349950.png


If you look further, you will see the warning message "The static field BA.cul should be accessed in a static way". That has been solved by replacing ba with the static BA.

// String eventName = event.concat("_").concat(baseEvent).toLowerCase(ba.cul);
String eventName = event.concat("_").concat(baseEvent).toLowerCase(BA.cul);
if (ba.subExists(eventName)) {
I recommend that you resolve all errors and all warnings reported by Eclipse before using SLC to generate the JAR and XML help file.

You can use the Eclipse project directory (in my case, M3SIP directory) as the source address for the SLC code.

Another thought is about the Russian PJSIP.jar file. I can't find a version in this jar file. On VoiSmart / pjsip-android on GitHub there is talk of version 2.11.1 and on Maven the 1.0 version can be seen. Because to avoid running into already solved "challenges" I advise you to compile the source code from GitHub.
 
Top