英文:
I use .so library and get NoSuchMethodError error
问题
我使用.so库,如下所示:
package ru.integrics.mobileschool.view.activity;
import android.util.Base64;
public class MainActivity {
public MainActivity(){
System.loadLibrary("x2");
}
public native String x01(String str);
public String get(String str){
String key = Base64.encodeToString(x01(str.substring(0, str.length() / 2)).getBytes(), Base64.NO_WRAP);
return key;
}
}
但是我得到了错误:
JNI DETECTED ERROR IN APPLICATION:
JNI CallObjectMethodV called with pending exception java.lang.NoSuchMethodError:
no non-static method "Lru/integrics/mobileschool/view/activity/MainActivity;.getPackageManager()Landroid/content/pm/PackageManager;"
我尝试将方法设置为静态,但不起作用。
英文:
I use .so library, as this
package ru.integrics.mobileschool.view.activity;
import android.util.Base64;
public class MainActivity {
public MainActivity(){
System.loadLibrary("x2");
}
public native String x01(String str);
public String get(String str){
String key = Base64.encodeToString(x01(str.substring(0, str.length() / 2)).getBytes(), Base64.NO_WRAP);
return key;
}
}
But i get error:
JNI DETECTED ERROR IN APPLICATION:
JNI CallObjectMethodV called with pending exception java.lang.NoSuchMethodError:
no non-static method "Lru/integrics/mobileschool/view/activity/MainActivity;.getPackageManager()Landroid/content/pm/PackageManager;"
I tried set methods static, but not working
答案1
得分: 0
您将System.loadLibrary("x2");
放错了地方。您应该将它放在一个静态代码块中:
package ru.integrics.mobileschool.view.activity;
import android.util.Base64;
public class MainActivity {
static {
System.loadLibrary("x2");
}
public MainActivity(){
...
}
public native String x01(String str);
public String get(String str){
String key = Base64.encodeToString(x01(str.substring(0, str.length() / 2)).getBytes(), Base64.NO_WRAP);
return key;
}
}
之后,您需要确认您已正确添加了libx2.so
并且存在一个x01(String)
函数。
英文:
You are placing System.loadLibrary("x2");
wrongly. You should place it in a static block instead:
package ru.integrics.mobileschool.view.activity;
import android.util.Base64;
public class MainActivity {
static {
System.loadLibrary("x2");
}
public MainActivity(){
...
}
public native String x01(String str);
public String get(String str){
String key = Base64.encodeToString(x01(str.substring(0, str.length() / 2)).getBytes(), Base64.NO_WRAP);
return key;
}
}
And after that you have to confirm you have properly added libx2.so
and there is a x01(String)
function inside.
答案2
得分: 0
如果您阅读错误信息,您会发现它在抱怨一个缺少的Java方法,因为您的MainActivity
类没有继承android.app.Activity
类,该类提供了所需的getPackageManager
方法。
英文:
If you read the error you see it is complaining about a missing Java method because your MainActivity
class does not inherit from the android.app.Activity
class, which provides the required getPackageManager
method.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论