2016-03-28 10 views
1

私はlogcatで、次のエラーを取得しています:Android ExceptionInitializeErrorを削除するには?

03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime: FATAL EXCEPTION: main 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime: Process: in.aekansh.cortibae, PID: 27708 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime: java.lang.ExceptionInInitializerError 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at in.aekansh.cortibae.MainActivity.onCreate(MainActivity.java:130) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.Activity.performCreate(Activity.java:5990) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2310) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2419) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread.access$900(ActivityThread.java:154) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:102) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:135) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:5293) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Native Method) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:372) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources in.aekansh.cortibae.App.getResources()' on a null object reference 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at in.aekansh.cortibae.AndroidUtilities.<clinit>(AndroidUtilities.java:32) 
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at in.aekansh.cortibae.MainActivity.onCreate(MainActivity.java:130)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.Activity.performCreate(Activity.java:5990)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2310)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2419)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread.access$900(ActivityThread.java:154)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.os.Handler.dispatchMessage(Handler.java:102)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.os.Looper.loop(Looper.java:135)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at android.app.ActivityThread.main(ActivityThread.java:5293)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Native Method)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at java.lang.reflect.Method.invoke(Method.java:372)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)  
03-28 15:07:12.758 27708-27708/in.aekansh.cortibae E/AndroidRuntime:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)  
03-28 15:07:14.863 27708-27708/in.aekansh.cortibae I/Process: Sending signal. PID: 27708 SIG: 9 

私はエラーを削除する方法を知りません。

これは私のMainActivity.javaです:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    AndroidUtilities.statusBarHeight = getStatusBarHeight(); 

    chatMessages = new ArrayList<>(); 

    chatListView = (ListView) findViewById(R.id.chat_list_view); 

    chatEditText1 = (EditText) findViewById(R.id.chat_edit_text1); 
    enterChatView1 = (ImageView) findViewById(R.id.enter_chat1); 

    // Hide the emoji on click of edit text 
    chatEditText1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      if (showingEmoji) 
       hideEmojiPopup(); 
     } 
    }); 


    emojiButton = (ImageView)findViewById(R.id.emojiButton); 

    emojiButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      showEmojiPopup(!showingEmoji); 
     } 
    }); 

    listAdapter = new ChatListAdapter(chatMessages, this); //load the messages from the array. 

    chatListView.setAdapter(listAdapter); 

    chatEditText1.setOnKeyListener(keyListener); 

    enterChatView1.setOnClickListener(clickListener); 

    chatEditText1.addTextChangedListener(watcher1); 

    sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout) findViewById(R.id.chat_layout); 
    sizeNotifierRelativeLayout.delegate = this; 

    NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded); 
} 

AndroidUtilities.java:

public class AndroidUtilities { 

    public static float density = 1; 
    public static int statusBarHeight = 0; 
    public static Point displaySize = new Point(); 

    static { 
     density = App.getInstance().getResources().getDisplayMetrics().density; 
     checkDisplaySize(); 
    } 

    public static int dp(float value) { 
     return (int)Math.ceil(density * value); 
    } 

    public static void runOnUIThread(Runnable runnable) { 
     runOnUIThread(runnable, 0); 
    } 

    public static void runOnUIThread(Runnable runnable, long delay) { 
     if (delay == 0) { 
      App.applicationHandler.post(runnable); 
     } else { 
      App.applicationHandler.postDelayed(runnable, delay); 
     } 
    } 

    public native static void loadBitmap(String path, Bitmap bitmap, int scale, int width, int height, int stride); 


    public static boolean copyFile(InputStream sourceFile, File destFile) throws IOException { 
     OutputStream out = new FileOutputStream(destFile); 
     byte[] buf = new byte[4096]; 
     int len; 
     while ((len = sourceFile.read(buf)) > 0) { 
      Thread.yield(); 
      out.write(buf, 0, len); 
     } 
     out.close(); 
     return true; 
    } 

    public static boolean copyFile(File sourceFile, File destFile) throws IOException { 
     if(!destFile.exists()) { 
      destFile.createNewFile(); 
     } 
     FileChannel source = null; 
     FileChannel destination = null; 
     try { 
      source = new FileInputStream(sourceFile).getChannel(); 
      destination = new FileOutputStream(destFile).getChannel(); 
      destination.transferFrom(source, 0, source.size()); 
     } catch (Exception e) { 
      //FileLog.e("tmessages", e); 
      return false; 
     } finally { 
      if(source != null) { 
       source.close(); 
      } 
      if(destination != null) { 
       destination.close(); 
      } 
     } 
     return true; 
    } 

    public static void checkDisplaySize() { 
     try { 
      WindowManager manager = (WindowManager) App.getInstance().getSystemService(Context.WINDOW_SERVICE); 
      if (manager != null) { 
       Display display = manager.getDefaultDisplay(); 
       if (display != null) { 
        if (android.os.Build.VERSION.SDK_INT < 13) { 
         displaySize.set(display.getWidth(), display.getHeight()); 
        } else { 
         display.getSize(displaySize); 
        } 
       } 
      } 
     } catch (Exception e) { 
     } 
    } 

    public static int getViewInset(View view) { 
     if (view == null || Build.VERSION.SDK_INT < 21) { 
      return 0; 
     } 
     try { 
      Field mAttachInfoField = View.class.getDeclaredField("mAttachInfo"); 
      mAttachInfoField.setAccessible(true); 
      Object mAttachInfo = mAttachInfoField.get(view); 
      if (mAttachInfo != null) { 
       Field mStableInsetsField = mAttachInfo.getClass().getDeclaredField("mStableInsets"); 
       mStableInsetsField.setAccessible(true); 
       Rect insets = (Rect)mStableInsetsField.get(mAttachInfo); 
       return insets.bottom; 
      } 
     } catch (Exception e) { 
      // FileLog.e("tmessages", e); 
     } 
     return 0; 
    } 



} 

私はNullPointerExceptionがどこを取得しています教えてください。私はsuper.onCreate();の後にすべての必要な機能を呼んだと思うので、何か問題があるはずはないと思います。私を助けてください。必要な場合は、私に詳細情報を求めてください。

******* ******* UPDATE
App.java:

public class App extends Application { 

    private static App Instance; 
    public static volatile Handler applicationHandler = null; 

    @Override 
    public void onCreate() { 
     super.onCreate(); 

     Instance=this; 

     applicationHandler = new Handler(getInstance().getMainLooper()); 

     NativeLoader.initNativeLibs(App.getInstance()); 

    } 

    public static App getInstance() 
    { 
     return Instance; 
    } 
} 
+0

App.getInstance()がnullを返すようです。 App.Javaコード – Entreco

+0

を追加してください。うまくいけば、これが役に立ちます。 –

答えて

0

あなたApp.getInstance()はnullを返しています。ここでの問題はAndroidUtilities.javaに静的ブロック符号である:

static { 
    density = App.getInstance().getResources().getDisplayMetrics().density; 
    checkDisplaySize(); 
} 

静的初期化ブロックは、JVM(クラスローダ - 具体的には)ときに実行される(それがコードで参照される最初の時間に発生)StaticClassをロードしアプリケーションが起動する前に(onCreate()のAppクラスメソッドが呼び出される前に)、herehereで詳細を読むことができます。

public class App extends Application { 

    public void onCreate() { 
     super.onCreate() 
     Instance = this; 
     AndroidUtilities.init(); 

     // your other code 
    } 
} 
+0

私はこれをしました: 'private MainActivity Instance; @オーバーライド protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); インスタンス= this; AndroidUtilities.init(); //他のコード } ' でも同じエラーが表示されます。 –

+0

MainActivity.javaではなくApp.javaで追加し、静的コードブロックを削除します – tjeubaoit

+0

まあ、私の悪いです。よかった。私はそれをしました。今度はExceptionInInitializerErrorがなくなりましたが、新しいエラーが発生しました: '03-28 16:20:01.826 3864-3864/in.aekansh.cortibae E/AndroidRuntime:致命的除外:メイン 03-28 16:20: 01.826 3864-3864/in.aekansh.cortibae E/AndroidRuntime:プロセス:in.aekansh.cortibae、PID:3864 03-28 16:20:01.826 3864-3864/in.aekansh.cortibae E/AndroidRuntime:java.lang .NullPointerException:ヌルオブジェクト参照で仮想メソッド 'java.lang.Object in.aekansh.cortibae.App.getSystemService(java.lang.String)'を呼び出そうとしました。 ... ' –

0

Androidのマニフェストは、アプリケーションをチェックアンドロイド追加:名=」

溶液をAndroidUtilities.javaで静的メソッドを静的コードブロックの上方に取り外して作成

public class AndroidUtilities { 

    public static float density = 1; 
    public static int statusBarHeight = 0; 
    public static Point displaySize = new Point(); 

    public static void init() { 
     density = App.getInstance().getResources().getDisplayMetrics().density; 
     checkDisplaySize(); 
    } 

    // your other code 
} 

App.javaあります.App "android:allowBackup =" true "と許可

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"></uses-permission> 

<application 
     android:name=".App" 
     android:allowBackup="true" 
     android:supportsRtl="true" 

アクティビティadd windowSoftInputMode属性

<activity 
      android:name=".UserChatActivity" 
      android:windowSoftInputMode="adjustResize"></activity> 

GrandleコントロールuseLibraryとsourceSets.main

useLibrary 'org.apache.http.legacy' 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

    sourceSets.main { 
     jniLibs.srcDir 'libs' 
     jni.srcDirs = [] //disable automatic ndk-build call 
    } 

Rebuid。

関連する問題