简体   繁体   中英

Java call function in .jar

I have a crash in my java application.

It happens when I try to call a static method from a class implemented in .jar file.

Here the error :

02-28 15:38:55.712: ERROR/AndroidRuntime(323): java.lang.NoClassDefFoundError: TOOLS.CLog

Here call to my function :

mylog=CLog.getInstance();

Here my class in .jar :

public class CLog implements iLog {
static private CLog m_instance=null;
public static iLog getInstance() {
    if (m_instance==null) {
        m_instance=new CLog();
    }
    return m_instance;
}

Some help please.

EDIT :

my classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

it should be (note package)

package TOOLS;
public class CLog implements iLog {
static private CLog m_instance=null;
public static iLog getInstance() {
    if (m_instance==null) {
        m_instance=new CLog();
    }
    return m_instance;
}

import class with fully qualified valid name

Is the jar with TOOLS package in the libs/ directory, so that it gets deployed on to the device along with the other classes? The error does not come from classpath settings in Eclipse, but rather from the device, which does not find the class.

The default tooling will package the jar with your app automatically when it is in the libs/ folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM