2016-06-14 16 views
5

顔を確認できるAndroidアプリケーションを作成しようとしていますが、私のエミュレータで(Eclipseを使用して)自分のアプリを実行しようとすると、ログカットにこの結果があります:Androidのjava.lang.ExceptionInInitializerError

次のように
 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); 
    } 

} 

どのように私はこの例外を解決することができますか?どんな助言も大きな助けになる。

答えて

2

こんにちは私の問題は解決しました。私は自分のプロジェクトにjna-4.2.2.jarを追加する必要があります。 jna.jarのネイティブライブラリに関するエラーがあります。この場合、Eclipseではに移動する必要があります。環境設定> Android>ビルド>「外部JARにネイティブライブラリが含まれているとエラーが発生します」のチェックをはずしてください。それから私の問題は解決されます。

0

私はこの権利を読んでいる場合、それはあなたのプロジェクトのプロパティでEclipseでJavaネイティブ・アクセス・プラットフォーム

ためのライブラリを見つけることができませんが、ライブラリを確認するためのJNAプラットフォーム

にjava.lang.ClassNotFoundException:COM .sun.jna.Platform

日食を使用してから数年が経ちました。

+0

jna.jarファイルをインストールしますか? –

+0

http://stackoverflow.com/questions/2824515/how-to-add-external-library-properly-in-eclipse http://mvnrepository.com/artifact/net.java.dev.jna/jna -platform/4.1.0 –

+0

質問が編集されます。いくつかの変更を例外エラーに入れる必要があります。 –

0

私は正しいライブラリがある場合、https://github.com/java-native-access/jna/tree/master/libとなる可能性のある依存関係を追加する必要があります。

これを行うには、Eclipseでプロジェクトを右クリックし、次にプロパティ(下のオプションにする必要があります)に移動します。

左側にいくつかのオプションがありますが、「Java Build Path」を選択してください。ここで、「Add Jars」または「Add External Jars」を追加できます。 Add External Jarを選択すると、フォルダプロジェクト内にインストールできるJarの追加を選択するとどこからでもインストールできます。私はプロジェクトフォルダ内にjarフォルダを追加し、別のフォルダにjarファイルを移動した場合は、Jarファイルの依存関係を設定します。

そこにあるリンクとサブリンクからすべてのjarファイルを追加します。それが問題を解決するかどうかを確認してください。 Eclipseには、クラスの依存関係がない場合は教えられますが、コードを実行するまで依存関係に依存しているかどうかは分かりません。

+0

あなたが提供したリンクのjarファイルをすべてインポートする必要がありますか? –

+0

はい、それを試して、それが動作するかどうかを確認してください。他にもdistフォルダにあるjarをダウンロードしようと提案されたようにhttps://github.com/java-native-access/jna/tree/master/dist – applecrusher

+0

私はこれをすべてダウンロードしました。しかし、このエラーが発生する可能性があります –

0

すでに他の人に指摘されているように、Java Native Access (JNA)というプロジェクトへの依存関係はありません。 StackTraceを注意深く見ると、最後にこの例外が表示されます。java.lang.NoClassDefFoundError: com.sun.jna.Platform。短いGoogle検索が上記のリポジトリで終了しました。

私はdownload all related jarsにAndroidの接頭辞を付けてみます。 android-arm.jarが必要な場合もありますが、これは別のプロセッサを搭載したデバイス上で破損するため、すべて追加してください。

0

ここに回答がありますので、今解決する方法を知っています。しかしこれは他人のためのものです。 Javaは大きな例外メッセージ処理機能を備えており、修正する必要があるものをほとんどすべて見つけることができます。これは私の意見とアドバイスです: 毎回見てください:部分。

例外がある場合は、最後にメッセージが原因で発生したものを見てください。たとえば、次のようになります。原因:java.lang.NoClassDefFoundError:com.sun.jna.Platform。 Javaには多くのエラークラスがあります。これはObject-> Throwable->Error-> LinkageErrorのエラーです。 Error =>ランタイム中に問題が発生しました。クラスが見つかりませんDef Found Errorはクラスローダーの一般的な問題です。エラーを説明するために必要なものはすべてjavaドキュメントにあります。


コメントのあなたの意見から、ここに外部ライブラリを追加するソリューションです。 Eclipseでライブラリをプロジェクトに追加する方法を

:ここでは他の人によってdecsribedさ ダウンロードジャー(jna.jar)とのlibフォルダに追加して、あなたは(パスを構築するためにそれを追加する必要があり、その後クラスローダそれを見つけることができ、あなたの問題を解決します)。 Eclipseを使用している場合は、Eclipse経由で直接libフォルダにインポートすることができます(プロジェクトフォルダを右クリックし、buildpath、ライブラリタブを選択してjarを追加します)、libフォルダにjarを直接コピーして、ビルドパスに。

+0

プロジェクトでjna-platform-4.1.0.jarをインポートしましたが、このエラーが発生します。 –

+0

依存関係を再現しましたか? – Hrabosch

+0

おそらく両方をダウンロードしてください。 jna.jarとjna-platform.jar、ここにJNA.jarがありますhttp://search.maven.org/#artifactdetails%7Cnet.java.dev.jna%7Cjna%7C4.2.2%7C – Hrabosch

関連する問題