Android get Status Bar Height giving java.lang.ExceptionInInitializerError -


additional information (the original question below)

after following @ρяσѕρєяk advice in comments section, getting same error on file (sizenotifierrelativelayout.java) , error occurs @ line 44, super.onlayout(changed, l, t, r, b);. code file , logcat follows:

sizenotifierrelativelayout.java

package com.app.name.widgets;  import android.content.context; import android.graphics.rect; import android.view.view; import android.widget.relativelayout;  import com.app.name.androidutilities;   public class sizenotifierrelativelayout extends relativelayout {      private rect rect = new rect();     public sizenotifierrelativelayoutdelegate delegate;      public abstract interface sizenotifierrelativelayoutdelegate {         public abstract void onsizechanged(int keyboardheight);     }      public sizenotifierrelativelayout(context context) {         super(context);     }      public sizenotifierrelativelayout(context context, android.util.attributeset attrs) {         super(context, attrs);     }      public sizenotifierrelativelayout(context context, android.util.attributeset attrs, int defstyle) {         super(context, attrs, defstyle);     }      @override     protected void onlayout(boolean changed, int l, int t, int r, int b) {         super.onlayout(changed, l, t, r, b);         if (delegate != null) {             view rootview = this.getrootview();             int usableviewheight = rootview.getheight() - androidutilities.statusbarheight - androidutilities.getviewinset(rootview);             this.getwindowvisibledisplayframe(rect);             int keyboardheight = usableviewheight - (rect.bottom - rect.top);             delegate.onsizechanged(keyboardheight);         }     } } 

logcat

10-15 09:09:57.918  23530-23530/? w/system.err﹕ @     com.app.name.widgets.sizenotifierrelativelayout.onlayout(sizenotifierrelativelayout.java:44) 10-15 09:09:57.927  23530-23530/? e/androidruntime﹕ fatal exception: main java.lang.nullpointerexception         @ android.widget.abslistview.obtainview(abslistview.java:2247)         @ android.widget.listview.makeandaddview(listview.java:1849)         @ android.widget.listview.filldown(listview.java:678)         @ android.widget.listview.fillfromtop(listview.java:739)         @ android.widget.listview.layoutchildren(listview.java:1664)         @ android.widget.abslistview.onlayout(abslistview.java:2050)         @ android.view.view.layout(view.java:14243)         @ android.view.viewgroup.layout(viewgroup.java:4490)         @ android.widget.relativelayout.onlayout(relativelayout.java:1021)         @ com.app.name.widgets.sizenotifierrelativelayout.onlayout(sizenotifierrelativelayout.java:44)         @ android.view.view.layout(view.java:14243)         @ android.view.viewgroup.layout(viewgroup.java:4490)         @ android.widget.framelayout.onlayout(framelayout.java:448)         @ android.view.view.layout(view.java:14243)         @ android.view.viewgroup.layout(viewgroup.java:4490)         @ android.widget.linearlayout.setchildframe(linearlayout.java:1670)         @ android.widget.linearlayout.layoutvertical(linearlayout.java:1528)         @ android.widget.linearlayout.onlayout(linearlayout.java:1441)         @ android.view.view.layout(view.java:14243)         @ android.view.viewgroup.layout(viewgroup.java:4490)         @ android.widget.framelayout.onlayout(framelayout.java:448)         @ android.view.view.layout(view.java:14243)         @ android.view.viewgroup.layout(viewgroup.java:4490)         @ android.widget.linearlayout.setchildframe(linearlayout.java:1670)         @ android.widget.linearlayout.layoutvertical(linearlayout.java:1528)         @ android.widget.linearlayout.onlayout(linearlayout.java:1441)         @ android.view.view.layout(view.java:14243)         @ android.view.viewgroup.layout(viewgroup.java:4490)         @ android.widget.framelayout.onlayout(framelayout.java:448)         @ android.view.view.layout(view.java:14243)         @ android.view.viewgroup.layout(viewgroup.java:4490)         @ android.view.viewrootimpl.performlayout(viewrootimpl.java:2230)         @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1994)         @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1181)         @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:4942)         @ android.view.choreographer$callbackrecord.run(choreographer.java:776)         @ android.view.choreographer.docallbacks(choreographer.java:579)         @ android.view.choreographer.doframe(choreographer.java:548)         @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:762)         @ android.os.handler.handlecallback(handler.java:800)         @ android.os.handler.dispatchmessage(handler.java:100)         @ android.os.looper.loop(looper.java:194)         @ android.app.activitythread.main(activitythread.java:5370)         @ java.lang.reflect.method.invokenative(native method)         @ java.lang.reflect.method.invoke(method.java:525)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600)         @ dalvik.system.nativestart.main(native method) 

orginal question-> have statusbar height function giving me a

fatal exception: main java.lang.exceptionininitializererror

the error set of when myactivity calls

androidutilities.statusbarheight = getstatusbarheight(); 

the function corresponding error:

at com.app.name.androidutilities.(androidutilities.java:31)

is

density = app.getinstance().getresources().getdisplaymetrics().density; 

as relatively new android , java, appreciate pointers missing. thanks!

myactivity.java

package com.app.name;  import com.app.name.widgets.sizenotifierrelativelayout;  public class myactivity extends actionbaractivity implements isidenavigationcallback, sizenotifierrelativelayout.sizenotifierrelativelayoutdelegate, notificationcenter.notificationcenterdelegate {      private sizenotifierrelativelayout sizenotifierrelativelayout;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.my_layout);          androidutilities.statusbarheight = getstatusbarheight();          sizenotifierrelativelayout = (sizenotifierrelativelayout) findviewbyid(r.id.chat_layout);         sizenotifierrelativelayout.delegate = this;          notificationcenter.getinstance().addobserver(this, notificationcenter.emojididloaded);     }      /**      * system status bar height      * @return      */     public int getstatusbarheight() {         int result = 0;         int resourceid = getresources().getidentifier("status_bar_height", "dimen", "android");         if (resourceid > 0) {             result = getresources().getdimensionpixelsize(resourceid);         }         return result;     } } 

app.java

package com.app.name;  import android.app.application; import android.os.handler;  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;     } } 

androidutilities.java

package com.app.name;  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();     } } 

logcat

10-15 07:57:41.119  15076-15076/? w/system.err? @ com.app.name.myactivity.oncreate(myactivity.java:197) 10-15 07:57:41.130  15076-15076/? w/system.err? @ com.app.name.androidutilities.<clinit>(androidutilities.java:31) 10-15 07:57:41.145  15076-15076/? e/androidruntime? fatal exception: main     java.lang.exceptionininitializererror             @ com.app.name.myactivity.oncreate(myactivity.java:197)             @ android.app.activity.performcreate(activity.java:5122)             @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1150)             @ android.app.activitythread.performlaunchactivity(activitythread.java:2315)             @ android.app.activitythread.handlelaunchactivity(activitythread.java:2403)             @ android.app.activitythread.access$600(activitythread.java:165)             @ android.app.activitythread$h.handlemessage(activitythread.java:1373)             @ android.os.handler.dispatchmessage(handler.java:107)             @ android.os.looper.loop(looper.java:194)             @ android.app.activitythread.main(activitythread.java:5370)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:525)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:600)             @ dalvik.system.nativestart.main(native method)      caused by: java.lang.nullpointerexception             @ com.app.name.androidutilities.<clinit>(androidutilities.java:31)             at com.app.name.myactivity.oncreate(myactivity.java:197)             at android.app.activity.performcreate(activity.java:5122)             at android.app.instrumentation.callactivityoncreate(instrumentation.java:1150)             at android.app.activitythread.performlaunchactivity(activitythread.java:2315)             at android.app.activitythread.handlelaunchactivity(activitythread.java:2403)             at android.app.activitythread.access$600(activitythread.java:165)             at android.app.activitythread$h.handlemessage(activitythread.java:1373)             at android.os.handler.dispatchmessage(handler.java:107)             at android.os.looper.loop(looper.java:194)             at android.app.activitythread.main(activitythread.java:5370)             at java.lang.reflect.method.invokenative(native method)             at java.lang.reflect.method.invoke(method.java:525)             at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:833)             at com.android.internal.os.zygoteinit.main(zygoteinit.java:600)             at dalvik.system.nativestart.main(native method) 


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -