android - TextView problems -


(1)

@override        protected void oncreate(bundle savedinstancestate)      {         super.oncreate(savedinstancestate);         setcontentview(r.layout.game);          health = (textview) findviewbyid(r.id.lblhealth);         gold = (textview) findviewbyid(r.id.lblgold);         steel = (textview) findviewbyid(r.id.lblsteel);         wood = (textview) findviewbyid(r.id.lblwood);          health.settext("fsdfsd");       } 

(2)

@override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          txt = (textview) findviewbyid(r.id.txtv);         txt.settext("fsddfs");     } 

why first(1) not work , second works?

in first activity im asking user press button, im using intent go layout , there im getting force close error ? hell?

07-01 14:29:17.321: error/androidruntime(1384): uncaught handler: thread main exiting due uncaught exception 07-01 14:29:17.371: error/androidruntime(1384): java.lang.runtimeexception: unable instantiate activity componentinfo{com.androstrategy/com.androstrategy.game}: java.lang.nullpointerexception 07-01 14:29:17.371: error/androidruntime(1384):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2497) 07-01 14:29:17.371: error/androidruntime(1384):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2621) 07-01 14:29:17.371: error/androidruntime(1384):     @ android.app.activitythread.access$2200(activitythread.java:126) 07-01 14:29:17.371: error/androidruntime(1384):     @ android.app.activitythread$h.handlemessage(activitythread.java:1932) 07-01 14:29:17.371: error/androidruntime(1384):     @ android.os.handler.dispatchmessage(handler.java:99) 07-01 14:29:17.371: error/androidruntime(1384):     @ android.os.looper.loop(looper.java:123) 07-01 14:29:17.371: error/androidruntime(1384):     @ android.app.activitythread.main(activitythread.java:4595) 07-01 14:29:17.371: error/androidruntime(1384):     @ java.lang.reflect.method.invokenative(native method) 07-01 14:29:17.371: error/androidruntime(1384):     @ java.lang.reflect.method.invoke(method.java:521) 07-01 14:29:17.371: error/androidruntime(1384):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:860) 07-01 14:29:17.371: error/androidruntime(1384):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:618) 07-01 14:29:17.371: error/androidruntime(1384):     @ dalvik.system.nativestart.main(native method) 07-01 14:29:17.371: error/androidruntime(1384): caused by: java.lang.nullpointerexception 07-01 14:29:17.371: error/androidruntime(1384):     @ com.androstrategy.game.<init>(game.java:75) 07-01 14:29:17.371: error/androidruntime(1384):     @ java.lang.class.newinstanceimpl(native method) 07-01 14:29:17.371: error/androidruntime(1384):     @ java.lang.class.newinstance(class.java:1479) 07-01 14:29:17.371: error/androidruntime(1384):     @ android.app.instrumentation.newactivity(instrumentation.java:1021) 07-01 14:29:17.371: error/androidruntime(1384):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2489) 07-01 14:29:17.371: error/androidruntime(1384):     ... 11 more 07-01 14:29:17.431: error/dalvikvm(1384): unable open stack trace file '/data/anr/traces.txt': permission denied 07-01 14:29:19.621: error/packageinstallationreceiver(247): remove /data/local/tmp/com.androstrategy.apk fail! 07-01 14:29:21.261: error/activitymanager(77): fail set top app changed! 

public class game extends activity { private static int res_health; private static int res_wood; private static int res_gold; private static int res_steel;

private static int stat_str; private static int stat_int; private static int stat_wit; private static int stat_maxhp; private static int stat_otvaga;  private static textview health; private static textview gold; private static textview steel; private static textview wood; 

try this..

health = (textview) findviewbyid(r.id.lblhealth);         gold = (textview) findviewbyid(r.id.lblgold);         steel = (textview) findviewbyid(r.id.lblsteel);         wood = (textview) findviewbyid(r.id.lblwood);          health.settext("fsdfsd"); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -