Java Question java.lang.NoClassDefFoundError !? :-/

Roeschti

Member
Licensed User
Longtime User
I'm playing around with an tiny implemetaion of the jcfis stuff. I wrote a library with a few methods (login, getFiles and so on).

I can compile everything without an error in Eclipse, but when I run my test app in B4A I alway get errors. Here is a small output of the logger:

Could not find class 'jcifs.smb.SmbFile', referenced from method thalmy.smbuddy.smbuddy.size
VFY: unable to resolve new-instance 395 (Ljcifs/smb/SmbFile;) in Lthalmy/smbuddy/smbuddy;
VFY: replacing opcode 0x22 at 0x0000
** Activity (main) Create, isFirst = true **
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x401b1760)
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: jcifs.UniAddress
at thalmy.smbuddy.smbuddy.login(smbuddy.java:41)
at thalmy.samba.main._activity_create(main.java:215)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:113)
at thalmy.samba.main.afterFirstLayout(main.java:84)
at thalmy.samba.main.access$100(main.java:16)
at thalmy.samba.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity thalmy.samba/.main


I have a reference of the external jcfis.jar in Eclipse and exported the lib as all others i've done before. This confuses me, don't know where I made a mistake. Thx for all tips
 

Roeschti

Member
Licensed User
Longtime User
Thanks for the hints. I added the annotation and checked the location of the jcfis.jar, but still got the same error.

Here's the full source of the lib:

B4X:
package thalmy.smbuddy;

import java.util.LinkedList;
import jcifs.UniAddress;
import jcifs.smb.*;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.keywords.Common;


@ShortName("SMBuddy") 
@Permissions(values={"android.permission.INTERNET"})
@Author("René Thalmann")
@Version((float) 1.00) 
@DependsOn(values={"jcfis"})



public class smbuddy {
   
   private UniAddress domain;
   private NtlmPasswordAuthentication authentication;
   
   public smbuddy()
   {
       //    
   }
   
    /**
     * @param address
     * @param username
     * @param password
     * @throws java.lang.Exception
     */
    public void login(String address, String username, String password) throws Exception
    {
       try {
          setDomain(UniAddress.getByName(address));
          setAuthentication(new NtlmPasswordAuthentication(address, username, password));
          SmbSession.logon(getDomain(), authentication);
       }
       catch (Exception e) {
            Common.Log("Failed Login: + e");
            //System.exit(1); 
           //NOTE exception or error here will close Android-application 
        }
       
    }
     
    /**
    *
    * @param path
    * @return linkedlist
    * @throws java.lang.Exception
    */
   public LinkedList<String> getList(String path) throws Exception
   {
       LinkedList<String> fList = new LinkedList<String>();
       //SmbFile f = new SmbFile(path,authentication);
       try {
       SmbFile f = new SmbFile(path);
       SmbFile[] fArr = f.listFiles();
       
          for(int a = 0; a < fArr.length; a++)
          {
              fList.add(fArr[a].getName());
              Common.Log(fArr[a].getName());
          }
       }
       
       catch (Exception e) {
           Common.Log("getList: + e");
           //System.exit(1); 
          //NOTE exception or error here will close Android-application 
       }
       

       return fList;
   }

   /**
    *
    * @param path
    * @return boolean
    * @throws java.lang.Exception
    */
   public boolean checkDirectory(String path) throws Exception
   {
       if(!isExist(path))
       {
           Common.Log(path + " not exist");
           return false;
       }

       if(!isDir(path))
       {
          Common.Log(path + " not a directory");
           return false;
       }

       return true;
   }

   /**
    *
    * @param path
    * @return boolean
    * @throws java.lang.Exception
    */
   public boolean isExist(String path) throws Exception
   {
       SmbFile sFile = new SmbFile(path, authentication);

       return sFile.exists();
   }

   /**
    *
    * @param path
    * @return boolean
    * @throws java.lang.Exception
    */
   public boolean isDir(String path) throws Exception
   {
       SmbFile sFile = new SmbFile(path, authentication);

       return sFile.isDirectory();
   }

   /**
    *
    * @param path
    * @throws java.lang.Exception
    */
   public void createDir(String path) throws Exception
   {
      SmbFile sFile = new SmbFile(path, authentication);

      sFile.mkdir();
   }

   /**
    *
    * @param path
    * @throws java.lang.Exception
    */
   public void delete(String path) throws Exception
   {
       SmbFile sFile = new SmbFile(path, authentication);
       sFile.delete();
   }

   /**
    *
    * @param path
    * @return long
    * @throws java.lang.Exception
    */
   public long size(String path) throws Exception
   {
       SmbFile sFile = new SmbFile(path, authentication);

       return sFile.length();
   }

   /**
    *
    * @param path
    * @return string
    * @throws java.lang.Exception
    */
   public String getFileName(String path) throws Exception
   {
       SmbFile sFile = new SmbFile(path, authentication);

       return sFile.getName();
   }

   /**
    * @return the domain
    */
   public UniAddress getDomain()
   {
       return domain;
   }

   /**
    * @param domain the domain to set
    */
   
   public void setDomain(UniAddress domain)
   {
       this.domain = domain;
   }
   

   /**
    * @return the authentication
    */
   public NtlmPasswordAuthentication getAuthentication()
   {
       return authentication;
   }

   /**
    * @param authentication the authentication to set
    */
   public void setAuthentication(NtlmPasswordAuthentication authentication)
   {
       this.authentication = authentication;
   }

}
 

Roeschti

Member
Licensed User
Longtime User
Solved...maybe

UniAdress and other things are available, but still got errors also without the login / authentification. So now I imported the full source of the jcifs into my library and now it works as it should. But the library grows a little...up to 400kb :eek:

I hope I can strip it down to the only needed things to make it smaller...

But thanks anyway
 
Top