CodeNameOne - NativeInterface - NativeLookup上的ClassNotFoundException

时间:2016-08-10 15:42:23

标签: java codenameone classnotfoundexception

我按照此视频https://www.codenameone.com/how-do-i---access-native-device-functionality-invoke-native-interfaces.html中的说明操作,但我的代码在查找行上抛出了java.lang.ClassNotFoundException:interfaces.MyNativeImpl。我使用的代码几乎与视频完全相同。

package interfaces;

import com.codename1.system.NativeInterface;

public interface MyNative extends NativeInterface{
    public String sayHi();
}

在android原生目录中

package interfaces;

public class MyNativeImpl {
    public String sayHi() {
        return "hi";
    }

    public boolean isSupported() {
        return true;
    }
}

并在java代码中:

    MyNative my = (MyNative)NativeLookup.create(MyNative.class);
    if(my != null && my.isSupported()){
        System.out.println("Hello!");
    }

我现在哪里出错?

1 个答案:

答案 0 :(得分:2)

这是完美的代码,可以在设备上运行。 您在模拟器中看到异常,因为运行时类路径中缺少native/internal_tmp目录,但除了桌面上没有本机接口之外,它不会引起问题:

enter image description here