gpt4 book ai didi

Android 中的 java.lang.ExceptionInInitializerError

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:58:04 27 4
gpt4 key购买 nike

我正在尝试创建一个可以验证人脸的 Android 应用程序但是当我尝试在我的模拟器(使用 Eclipse)上运行我的应用程序时,我的 logcat 中有这个结果:

       06-16 14:51:24.326: E/AndroidRuntime(4305): FATAL EXCEPTION: main
06-16 14:51:24.326: E/AndroidRuntime(4305): Process: com.neurotec.samples.faceverification, PID: 4305
06-16 14:51:24.326: E/AndroidRuntime(4305): java.lang.ExceptionInInitializerError
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.neurotec.view.NGui.<clinit>(NGui.java:56)
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.neurotec.view.NViewBase.<clinit>(NViewBase.java:30)
06-16 14:51:24.326: E/AndroidRuntime(4305): at java.lang.reflect.Constructor.constructNative(Native Method)
06-16 14:51:24.326: E/AndroidRuntime(4305): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:341)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.app.Activity.setContentView(Activity.java:1975)
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.neurotec.samples.faceverification.FaceVerificationApplication.onCreate(FaceVerificationApplication.java:46)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.app.Activity.performCreate(Activity.java:5370)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2422)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.app.ActivityThread.access$800(ActivityThread.java:151)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.os.Handler.dispatchMessage(Handler.java:110)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.os.Looper.loop(Looper.java:193)
06-16 14:51:24.326: E/AndroidRuntime(4305): at android.app.ActivityThread.main(ActivityThread.java:5330)
06-16 14:51:24.326: E/AndroidRuntime(4305): at java.lang.reflect.Method.invokeNative(Native Method)
06-16 14:51:24.326: E/AndroidRuntime(4305): at java.lang.reflect.Method.invoke(Method.java:515)
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
06-16 14:51:24.326: E/AndroidRuntime(4305): at dalvik.system.NativeStart.main(Native Method)
06-16 14:51:24.326: E/AndroidRuntime(4305): Caused by: java.lang.ExceptionInInitializerError
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.neurotec.media.NMedia.<clinit>(NMedia.java:49)
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.neurotec.view.NGui.<clinit>(NGui.java:47)
06-16 14:51:24.326: E/AndroidRuntime(4305): ... 26 more
06-16 14:51:24.326: E/AndroidRuntime(4305): Caused by: java.lang.ExceptionInInitializerError
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.neurotec.lang.NCore.<clinit>(NCore.java:140)
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.neurotec.lang.NTypes.<clinit>(NTypes.java:171)
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.neurotec.media.NMedia.<clinit>(NMedia.java:46)
06-16 14:51:24.326: E/AndroidRuntime(4305): ... 27 more
06-16 14:51:24.326: E/AndroidRuntime(4305): Caused by: java.lang.NoClassDefFoundError: com.sun.jna.Platform
06-16 14:51:24.326: E/AndroidRuntime(4305): at com.neurotec.lang.NCore.<clinit>(NCore.java:123)
06-16 14:51:24.326: E/AndroidRuntime(4305): ... 29 more

FaceVerificationApplication.java的代码如下:

public class FaceVerificationApplication extends BaseActivity implements
EnrollmentDialogListener, UserSelectionListener {

// ===========================================================
// Private fields
// ===========================================================

private static final String EXTRA_REQUEST_CODE = "request_code";
private static final int VERIFICATION_REQUEST_CODE = 1;
private static final int TIMEOUT = 60000;
private boolean mAppClosing;
private NFaceVerificationView mFaceView;

// ===========================================================
// Protected methods
// ===========================================================

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nlvdemo);
// on application start you must set NCore context
NCore.setContext(this);

new Thread(new Runnable() {

@Override
public void run() {
try {
showProgress(R.string.msg_initialising);

// get NFV for the first time
final NFaceVerification nfv = NFV.getInstance();

// load settings
SettingsFragment.loadSettings();

// button implementations
Button mEnrollButton = (Button) findViewById(R.id.button_enroll);
mEnrollButton
.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
EnrollmentDialogFragment enrollDialog = new EnrollmentDialogFragment();
enrollDialog.show(getFragmentManager(),
"enrollment");
}
});

Button mCancelButton = (Button) findViewById(R.id.button_cancel);
mCancelButton
.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
showProgress(R.string.msg_cancelling);
nfv.cancel();
hideProgress();
}
});

Button mVerifyButton = (Button) findViewById(R.id.button_verify);
mVerifyButton
.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putInt(EXTRA_REQUEST_CODE,
VERIFICATION_REQUEST_CODE);
UserListFragment userList = (UserListFragment) UserListFragment
.newInstance(nfv.getUsers(), true,
bundle);
userList.show(getFragmentManager(),
"verification");
}
});

// set frontal camera
String[] names = nfv.getAvailableCameraNames();
for (String n : names) {
if (n.contains("Front")) {
nfv.setCamera(n);
break;
}
}

mFaceView = (NFaceVerificationView) findViewById(R.id.nFaceView);
nfv.addCapturePreviewListener(new NFaceVerificationCapturePreviewListener() {

@Override
public void capturePreview(
NFaceVerificationCapturePreviewEvent arg0) {
mFaceView.setEvent(arg0);
}
});

hideProgress();
} catch (Exception ex) {
hideProgress();
showError(ex);
}
}

}).start();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.nlvdemo, menu);
return true;
}

@Override
public void onBackPressed() {
super.onBackPressed();
mAppClosing = true;
}

@Override
public void onEnrollmentIDProvided(final String id) {
new Thread(new Runnable() {

@Override
public void run() {
try {
// cancel in there are any other operations in progress
NFV.getInstance().cancel();
NFaceVerificationStatus status = NFV.getInstance().enroll(
id, TIMEOUT, null);
showInfo(String.format(
getString(R.string.msg_operation_status),
status.toString()));
} catch (Throwable e) {
showError(e);
}
}
}).start();
};

@Override
public void onUserSelected(final NFaceVerificationUser user, Bundle bundle) {
new Thread(new Runnable() {

@Override
public void run() {
try {
// cancel in there are any other operations in progress
NFV.getInstance().cancel();
NFaceVerificationStatus status = NFV.getInstance().verify(
user.getId(), TIMEOUT);
showInfo(String.format(
getString(R.string.msg_operation_status),
status.toString()));
} catch (Throwable e) {
showError(e);
}
}
}).start();
};

@Override
protected void onStop() {
if (mAppClosing) {
NFV.getInstance().cancel();
NFV.dispose();
}
super.onStop();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_clear_db) {
new Thread(new Runnable() {

@Override
public void run() {
// cancel if there are any other operations in progress
NFV.getInstance().cancel();
NFV.getInstance().getUsers().clear();
}
}).start();
return true;
} else if (id == R.id.action_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);

return true;
}
return super.onOptionsItemSelected(item);
}

}

如何解决这个异常?任何建议都有很大帮助。

最佳答案

这里有答案,所以你现在知道如何解决它了。但这是给别人的。 Java 有一个很棒的异常消息处理,您几乎可以在其中找到修复它所需的所有内容。这只是我的意见和建议:每次查看 CAUSED BY: 部分。

当您有异常时,请查看最后由消息引起的。例如这里是:Caused by: java.lang.NoClassDefFoundError: com.sun.jna.Platform。 Java 有很多错误类。这是 Object->Throwable->Error->LinkageError 的错误。 Error => Problem during runtime, No class Def Found Error 是类加载器的典型问题。解释错误所需的所有内容都在 Java 文档中。


顺便说一下,根据您在评论中的问题,这里是添加外部库的解决方案。

如何在 Eclipse 中添加库到项目:在此处下载其他人描述的 jar (jna.jar) 并将其添加到 lib 文件夹,然后您必须将其添加到构建路径(然后类加载器将能够找到它,它将解决您的问题问题)。如果您使用的是 Eclipse,您可以通过 Eclipse 将它们直接导入到您的 lib 文件夹(右键单击项目文件夹,选择构建路径,库选项卡并添加 jar)或者直接将 jar 复制到 lib 文件夹,然后右键单击并构建路径 -> 添加到构建路径。

关于Android 中的 java.lang.ExceptionInInitializerError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37804174/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com