当前位置: 首页 > 面试题库 >

Android中的java.lang.ExceptionInInitializerError

巩才捷
2023-03-14
问题内容

我正在尝试创建一个可以验证人脸的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);
    }

}

我该如何解决此异常?任何建议都会有很大帮助。


问题答案:

嗨,我的问题解决了。我必须将jna-4.2.2.jar添加到我的项目中。我在jna.jar中遇到有关本机库的错误。因此,在这种情况下,在Eclipse中,我必须转到
“首选项” >“ Android”>“构建”>取消选中“当外部jar包含本机库时出现强制错误”。然后我的问题解决了。



 类似资料:
  • 我的年级代码是: 请帮我解决这个问题。

  • 我已经为android Studio创建了一个webview应用程序。但没有加载web URL。错误为NET::ERR_ACCESS_DENIED。有谁能帮忙吗

  • 问题内容: 我需要在内部存储中打开包含图像的文件夹。 我使用以下代码。 java 路径 表现 xml / file_paths 错误 致命异常:主要过程:android.apps.bnb.company.myphotos,PID:22482 android.os.FileUriExposedException:file:/// storage / emulated / 0 / Pictures /

  • 问题内容: 我有很多文件的Java项目,正在使用LOG4J。现在,我正在尝试将其移植到Android平台。是否可以通过LOG4J函数调用按原样重用代码? 目前的理解: 属性配置不起作用(依赖于bean) 我尝试使用LOG4J for Android和SL4J Lib。没有成功 加工。但是没用 我想念什么吗?指向任何可行的例子? 问题答案: 通过使用android-logging- log4j.ja

  • 我有一个问题,找出我的源代码中的错误。 有什么办法可以解决它吗? 我的代码中抛出了“ArrayIndexOutOfBoundsException”,但我无法找到它的位置。 android studio中的logcat:

  • 问题内容: 有什么办法可以在android中执行吗? 我一直在网上看到所有内容,但是在android中找不到JSON类。 有什么帮助吗? 问题答案: 是Javascript函数,在Java中不可用。如果您使用的是Android SDK中内置的程序包,则等效的方法是只调用您的实例,或更人性化。 http://developer.android.com/reference/org/json/JSONO