我在Android上使用C ++和Java之间的桥梁,用于扫描android中的文件 所以我有疑问,我有错误
No implementation found for void com.example.Scanner.scan(java.lang.String) (tried Java_com_example_Scanner_scan and Java_com_example_Scanner_scan__Ljava_lang_String_2)
public class Scanner extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scan("sdcard/");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
native void scan(String path);
static {
System.loadLibrary("scanner");
}
}
void Java_com_example_Scanner_scan(JNIEnv* env, jclass cls, jstring path)
{
mJNI = env;
mObject = cls;
const char *scan_path = mJNI->GetStringUTFChars(path, 0);
scan(string(scan_path));
// Release string IMPORTANT For Java & C++
mJNI->ReleaseStringUTFChars(path, scan_path);
}
答案 0 :(得分:1)
你忘记了JNIexport和JNIcall。 这就是它应该是这样的:
JNIEXPORT void JNICALL Java_ClassName_MethodName
(JNIEnv *env, jobject obj)
{
/*Implement Native Method Here*/
}
所以对你来说应该是:
JNIEXPORT void JNICALL Java_com_example_Scanner_scan(JNIEnv* env, jclass cls, jstring path)
{
//do you things
}
您可以在此处找到一些不错的信息:wiki