Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法调用本机方法eclipse 我正在开发一个使用C++代码的Android应用程序。尝试使用JNI但失败。 这是我的密码: 从jni文件夹中的test.c: jstring Segment_com_example_segment_BrowsePicture_test( JNIEnv* env, jobject thiz ) { return (*env)->NewStringUTF(env, "test"); }_Android_C++_Eclipse - Fatal编程技术网

无法调用本机方法eclipse 我正在开发一个使用C++代码的Android应用程序。尝试使用JNI但失败。 这是我的密码: 从jni文件夹中的test.c: jstring Segment_com_example_segment_BrowsePicture_test( JNIEnv* env, jobject thiz ) { return (*env)->NewStringUTF(env, "test"); }

无法调用本机方法eclipse 我正在开发一个使用C++代码的Android应用程序。尝试使用JNI但失败。 这是我的密码: 从jni文件夹中的test.c: jstring Segment_com_example_segment_BrowsePicture_test( JNIEnv* env, jobject thiz ) { return (*env)->NewStringUTF(env, "test"); },android,c++,eclipse,Android,C++,Eclipse,我已经通过ndk构建并生成libtest.so。 但是在我的BrowsePicture.java中(在Segment.com.example.Segment下) 我补充说 public native String test(); 但我不能称之为。 信息是: E/AndroidRuntime(16748): java.lang.UnsatisfiedLinkError: Native method not found: com.example.segment.BrowsePicture.tes

我已经通过ndk构建并生成libtest.so。 但是在我的BrowsePicture.java中(在Segment.com.example.Segment下) 我补充说

public native String  test();
但我不能称之为。 信息是:

E/AndroidRuntime(16748): java.lang.UnsatisfiedLinkError: Native method not found: com.example.segment.BrowsePicture.test:()Ljava/lang/String;

有谁能告诉我出了什么问题吗?

您是否声明了另一个类似下面的类

package com.yourpackage;
public class NativeLib {

static {
    System.loadLibrary("yourlibrary");
}

public static native void your_function(your_arguments);
}
然后使用从活动中调用此函数

NativeLib.your_function(your_arguments);

是否通过以下方式加载库:

...
public class BrowsePicture {

    static {
        // assume that libtestjni.so is your lib file
        System.loadLibrary("testjni");
    }
...

尝试通过此更改方法名称

jstring Java_com_example_segment_BrowsePicture_test( JNIEnv* env, jobject thiz )
而不是这个

jstring Segment_com_example_segment_BrowsePicture_test( JNIEnv* env, jobject thiz )

是的,我添加了静态{System.loadLibrary(“test”);},并在我的主要活动中调用了它。我的make文件是LOCAL\u PATH:=$(调用我的dir)include$(清除变量)LOCAL\u模块:=测试本地\u SRC\u文件:=测试.c include$(构建共享\u库)方法的名称正确吗?我只是按照示例Hello jini所做的方式创建另一个类,而不是将其加载到MainActivity中。然后调用该方法。还要确保test.so受运行的CPU体系结构的支持。是的,我安装了,我的make文件是'LOCAL_PATH:=$(call my dir)include$(CLEAR_VARS)LOCAL_MODULE:=test LOCAL_SRC_FILES:=test.c include$(BUILD_SHARED_LIBRARY)'我加载了静态的{System.loadLibrary(“test”)}你在apk中包含了.so文件吗?(将.so文件放入项目的/libs/armeabi文件夹中,ADT会将其打包到apk中)。确定。我通常不会手动编写jni函数,而是使用javah生成.h文件。首先构建Android项目(java代码),然后启动命令行窗口并将目录更改为项目文件夹,然后运行“javah-classpath./bin/classes-jni com.example.helloworld.MyJni”,然后在项目文件夹(com\u example\u helloworld\u MyJni.h)中获得jni头文件。您可以用同样的方法生成自己的.h文件,并包含该文件,而不是编写自己的函数声明。非常感谢。我正在处理许多.cpp文件,很好,正如我所说的,您应该通过javah生成jni函数名以避免错误。请参阅我以前的评论,了解如何操作。