Declare Android layout elements globally -


i'd know if there's anyway declare activity's element globally. tried use view dummy, this:

private final view dummy = (view) view.inflate(this,r.layout.dummy,null); private final imagebutton imgbutton = dummy.findviewbyid(r.id.imgbutton); 

but application crashes everytime following message:

unable instantiate activity componentinfo 

since need them final (i'm using them on listeners), can't declare them globally , instantiate them inside oncreate method. hope guys can help.

here's android manifest file:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.tcc.ecalc"     android:versioncode="1"     android:versionname="1.0" >  <uses-sdk     android:minsdkversion="8"     android:targetsdkversion="21" />  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/appbasetheme" >      <activity         android:theme="@style/apptheme"          android:name=".activity_perfiltab">         <intent-filter>           <action android:name="android.intent.action.main" />           <category android:name="android.intent.category.launcher" />         </intent-filter>         </activity>      <activity          android:theme="@style/apptheme"          android:name=".activity_materialtab">        </activity>      <activity         android:name=".activity_main"         android:label="@string/app_name" >        </activity>  </application> 

not sure if that's guys need, here is.

e/androidruntime(1282): fatal exception: main e/androidruntime(1282): process: com.tcc.ecalc, pid: 1282 e/androidruntime(1282): java.lang.runtimeexception: unable instantiate activity componentinfo{com.tcc.ecalc/com.tcc.ecalc.activity_perfiltab}: java.lang.illegalstateexception: system services not available activities before oncreate()

at android.app.activitythread.performlaunchactivity(activitythread.java:2236)  @ android.app.activitythread.handlelaunchactivity(activitythread.java:2390)  @ android.app.activitythread.access$800(activitythread.java:151)  @ android.app.activitythread$h.handlemessage(activitythread.java:1303)  @ android.os.handler.dispatchmessage(handler.java:102)  @ android.os.looper.loop(looper.java:135)  @ android.app.activitythread.main(activitythread.java:5257)  @ java.lang.reflect.method.invoke(native method)  @ java.lang.reflect.method.invoke(method.java:372)  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903)  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698)  caused by: java.lang.illegalstateexception: system services not available activities before oncreate()  @ android.app.activity.getsystemservice(activity.java:5035)  @ android.view.layoutinflater.from(layoutinflater.java:219)  @ android.view.view.inflate(view.java:18531)  @ com.tcc.ecalc.activity_perfiltab.<init>(activity_perfiltab.java:17)  @ java.lang.reflect.constructor.newinstance(native method)  @ java.lang.class.newinstance(class.java:1606)  @ android.app.instrumentation.newactivity(instrumentation.java:1066)  @ android.app.activitythread.performlaunchactivity(activitythread.java:2226)

the activity code, not finished yet:

package com.tcc.ecalc;  import android.app.activity; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemselectedlistener; import android.widget.edittext; import android.widget.imagebutton; import android.widget.spinner; import android.widget.textview;  public class activity_perfiltab<perfilcursoradapter> extends activity {  private view dummy = (view) view.inflate(this, r.layout.activity_perfiltab, null); final spinner spnperfil = (spinner) dummy.findviewbyid(r.id.per_spn_perfil); final spinner spntipo = (spinner) dummy.findviewbyid(r.id.per_spn_tipo); final edittext nome = (edittext) dummy.findviewbyid(r.id.per_frm_nome); final edittext d0_frm = (edittext) dummy.findviewbyid(r.id.per_frm_d0);  final edittext d1_frm = (edittext) dummy.findviewbyid(r.id.per_frm_d1);  final edittext d2_frm = (edittext) dummy.findviewbyid(r.id.per_frm_d2);  final edittext d3_frm = (edittext) dummy.findviewbyid(r.id.per_frm_d3);  final edittext momi = (edittext) dummy.findviewbyid(r.id.per_frm_inercia); final edittext asec = (edittext) dummy.findviewbyid(r.id.per_frm_area); final textview d0_lbl = (textview) dummy.findviewbyid(r.id.per_lbl_d0); final textview d1_lbl = (textview) dummy.findviewbyid(r.id.per_lbl_d1); final textview d2_lbl = (textview) dummy.findviewbyid(r.id.per_lbl_d2); final textview d3_lbl = (textview) dummy.findviewbyid(r.id.per_lbl_d3); final imagebutton addmaterial = (imagebutton) dummy.findviewbyid(r.id.per_btn_add); final imagebutton excmaterial = (imagebutton) dummy.findviewbyid(r.id.per_btn_exc); final imagebutton atmaterial = (imagebutton) findviewbyid(r.id.per_btn_atualizar);   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_perfiltab);   createspnperfil(0); }  public void createspnperfil(int position) {     final sqlitedatabase estrutura = openorcreatedatabase("estrutura.db", getbasecontext().mode_private, null);     final cursor linha = estrutura.rawquery("select * perfis", null);     spnperfil.setadapter(new itemadapter(getbasecontext(),r.layout.spn_img,linha, 1,2,0,"per_icn_"));     spnperfil.setselection(position);     spnperfil.setonitemselectedlistener(new onitemselectedlistener() {          @override         public void onitemselected(adapterview<?> parent, view view, int position, long id) {             linha.movetoposition(position);             int tipo = linha.getint(2);             nome.settext(linha.getstring(1));             //todo arrumar aqui             //spntipo.setselection(linha.getint(2));             momi.settext(linha.getstring(4));             asec.settext(linha.getstring(3));             d0_frm.settext(linha.getstring(5));             d1_frm.settext(linha.getstring(6));             d2_frm.settext(linha.getstring(7));             d3_frm.settext(linha.getstring(8));              //atualiza o nome das labels e esconde aquelas que não são necessárias             switch(tipo) {             //seção geral             case 1: {                 d0_lbl.settext(r.string.area_label);                 d1_lbl.settext(r.string.inercia_label);                 d2_lbl.setvisibility(view.invisible);                 d3_lbl.setvisibility(view.invisible);             } break;             //seção circular             case 2: {                 d0_lbl.settext(r.string.diametro_label);             } break;             //seção retangular             case 3: {                 d0_lbl.settext(r.string.base_label);                 d1_lbl.settext(r.string.altura_label);             } break;             //seção circular vazada             case 4: {                 d0_lbl.settext(r.string.diametro_externo_label);                 d1_lbl.settext(r.string.espessura_label);             } break;             //seção retangular vazada             default : {                 d0_lbl.settext(r.string.base_label);                 d1_lbl.settext(r.string.altura_label);                 d2_lbl.settext(r.string.espessura_alma_label);                 d3_lbl.settext(r.string.espessura_mesa_label);             } break;             }         }         @override         public void onnothingselected(adapterview<?> parent) {}     }); } 

}

here problem private view dummy = (view) view.inflate(this, r.layout.activity_perfiltab, null); code need inside oncreate.

"system services not available activities before oncreate()"


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -