UnsatisfiedLinkError:No implementation found for java.lang.String com.skymaster.hs.test4.MainActivity.getstringFromJNI();

就是桌这个路径下的方法stringFromJNI();没有被实现,看看全部代码

public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
} @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // Example of a call to a native method
TextView tv = (TextView) findViewById(R.id.sample_text);
tv.setText(stringFromJNI());
tv.append(getStringFromJNI());
} /**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public native String stringFromJNI();
public native String getStringFromJNI();
}

下面是cpp目录中native-lib.cpp的代码

#include <jni.h>
#include <string>
using namespace std;
extern "C" jstring
Java_com_skymaster_hs_test4_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
} jstring
Java_com_skymaster_hs_test4_MainActivity_getStringFromJNI(
JNIEnv *env,
jobject /* this */) {
string hello = " Hello Android";
return env->NewStringUTF(hello.c_str());
}

这里虽然是c++的源文件,但是两个函数都是c的函数,所以需要用extern "C"(大写的C)来告诉c++编译器需要按照c的的方式来编译与链接。问题出在
extern "C"的作用范围,如果不用大括号包括2个函数就会出问题。修改如下就好了

#include <jni.h>
#include <string>
using namespace std;
extern "C" { jstring
Java_com_skymaster_hs_test4_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
} jstring
Java_com_skymaster_hs_test4_MainActivity_getStringFromJNI(
JNIEnv *env,
jobject /* this */) {
string hello = " Hello Android";
return env->NewStringUTF(hello.c_str());
}
}

Jni的一个异常的更多相关文章

  1. 吴恩达机器学习笔记54-开发与评价一个异常检测系统及其与监督学习的对比(Developing and Evaluating an Anomaly Detection System and the Comparison to Supervised Learning)

    一.开发与评价一个异常检测系统 异常检测算法是一个非监督学习算法,意味着我们无法根据结果变量

  2. Python: 如何写一个异常

    例子1 try: #test area function() except Exception, e: print e.message 例子2:用raise抛出一个异常 if bool_var is ...

  3. 从一个异常探索spring autowired 的原理

    从一个异常探索autowired 的原理. 首先环境是这样的: public class Boss { @Autowired private Car car; } //@Component 加上这个注 ...

  4. Python面向对象之异常捕获(一)-----抛出一个异常

    大部分的异常都继承自Exception这个类(而这个类有继承自BaseException这个类) 常见的异常 ValueError TypeError IndexError 抛出一个异常 下面这个类的 ...

  5. 如何开发一个异常检测系统:使用什么特征变量(features)来构建异常检测算法

    如何构建与选择异常检测算法中的features 如果我的feature像图1所示的那样的正态分布图的话,我们可以很高兴地将它送入异常检测系统中去构建算法. 如果我的feature像图2那样不是正态分布 ...

  6. MVC默认提供了一个异常过滤器 HandleErrorAttribte特性

    这一篇记录MVC默认提供了一个异常过滤器 HandleErrorAttribte,下一篇介绍自定义异常过滤特性. 参考引用:https://www.cnblogs.com/TomXu/archive/ ...

  7. Jni碰到的一个异常

    Java与C++都有String对象,而c没有,只有char类型,所以在向C传入String类型的时候,如何处理需要注意一点 jstring Java_com_skymaster_hs_test4_M ...

  8. Java Native Interface 六JNI中的异常

    本文是<The Java Native Interface Programmer's Guide and Specification>读书笔记 在这里只讨论调用JNI方法可能会出现的异常, ...

  9. 配置Entity Framework连接Sql Server出现的一个异常

    异常:The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFrame ...

随机推荐

  1. Can't create handler inside thread that has not called Looper.prepare()

    参考文章:http://stackoverflow.com/questions/7185942/error-while-dispaying-an-toast-message-cant-create-h ...

  2. itoa

    功能:把int转为字符数组 eg: int a=100: char ch[3]; itoa(a,ch,10)://十进制 ---->ch[0]==1;...

  3. 3-WebPack

    一. 什么是WebPack WebPack可以看做是模块加载.打包工具. 它所做的事情是 1.分析你的项目结构,找到JavaScript模块以及其它的一些浏览器不能直接运行的拓展语言(Scss,Typ ...

  4. Python3基础 用三个双引号 print输出多行文本

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  5. ruby学习总结02

    1.条件判断(nil或alse为假,其他值均为真) 1.if语句  if/elsif/else/end     条件成立时执行相关操作 2.unless语句   unless/else/end  条件 ...

  6. CodeForces 151B Phone Numbers

     Phone Numbers Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Sub ...

  7. PHP工作原理

    文章一 :http://blog.csdn.net/21aspnet/article/details/6973405 简介 先看看下面这个过程: 我们从未手动开启过PHP的相关进程,它是随着Apach ...

  8. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 二分

    C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input ...

  9. iOS - Swift NSTimer 定时器

    前言 public class NSTimer : NSObject 作用 在指定的时间执行指定的任务. 每隔一段时间执行指定的任务. 1.定时器的创建 当定时器创建完(不用 scheduled 的, ...

  10. FFPEG 转码记录------解决了有流,但是没有码率和FPS?

    命令行:(已经测试成功) ffmpeg -i rtmp://localhost/live/S0000_8 -c:v libx264 -b:v 500k -c:a libfdk_aac -b:a 64k ...