首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.setText函数引起的误差

.setText函数引起的误差
EN

Stack Overflow用户
提问于 2012-10-10 12:30:32
回答 4查看 630关注 0票数 0

文本视图上的.setText函数导致我的应用程序崩溃。据我所读,问题可能在于它不在UI线程上,但我不知道如何解决它

代码语言:javascript
复制
public class SingleMenuItemActivity  extends Activity {

TextView lblName;
TextView lblyest;
TextView lbltoday;
TextView lblHigh;
TextView lblLow;
TextView lblChange;
TextView lblPcchange;
Button set;

String name, yesterday, today, high, low, change, pcchange;

@Override
protected void onCreate (Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate( savedInstanceState );
    setContentView( R.layout.single_list_item);

    set=(Button) findViewById(R.id.btnSet);
    lblName =   (TextView) findViewById( R.id.name );
    lblyest = (TextView) findViewById( R.id.yesterday );
    lbltoday = (TextView) findViewById( R.id.today );
    lblHigh = (TextView) findViewById( R.id.high );
    lblLow = (TextView) findViewById( R.id.low );
    lblChange = (TextView) findViewById( R.id.change );
    lblPcchange = (TextView) findViewById( R.id.pcchange );


    Intent in = getIntent();

    name = in.getStringExtra( "name" );
    ;
    yesterday = in.getStringExtra( "yesterday" );
    today = in.getStringExtra( "today" );
    high = in.getStringExtra( "high" );
    low = in.getStringExtra( "low" );
    change = in.getStringExtra( "change" );
    pcchange = in.getStringExtra( "pcchange" );


            lblName.setText(name);
            lblyest.setText(yesterday);
            lbltoday.setText(today);
            lblHigh.setText(high);
            lblLow.setText(low);
            lblChange.setText(change);
            lblPcchange.setText(pcchange); 




}


}

不知道到底是什么问题

下面是日志:

代码语言:javascript
复制
10-10 15:37:14.544: I/ActivityManager(58): Starting activity: Intent { cmp=com.kmarima.knight/.SingleMenuItemActivity (has extras) }
10-10 15:37:18.217: D/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
10-10 15:37:24.613: W/ActivityManager(58): Launch timeout has expired, giving up wake lock!
10-10 15:37:24.685: W/ActivityManager(58): Activity idle timeout for HistoryRecord{45018590 com.kmarima.knight/.SingleMenuItemActivity}
10-10 15:37:29.874: D/dalvikvm(264): GC_EXPLICIT freed 2061 objects / 147656 bytes in 165ms
10-10 15:37:34.914: D/dalvikvm(296): GC_EXPLICIT freed 811 objects / 56944 bytes in 162ms

这里是活动开始的地方

代码语言:javascript
复制
             Intent in = new Intent(KnightActivity.this, SingleMenuItemActivity.class);
              in.putExtra("name", "The Name");
                 in.putExtra("yesterday", "Value For Yesterday");
                 in.putExtra("today", "Todays Value");
                 in.putExtra("high", "High Value");
                 in.putExtra("low", "Low Value");
                 in.putExtra("change", "Change Value");
                 in.putExtra("pcchange", "PC Change Value");

             startActivity(in);
EN

回答 4

Stack Overflow用户

发布于 2012-10-10 12:34:46

在setText中,您必须设置一些空值。它的错误在哪一行?请检查变量是否为空。

票数 0
EN

Stack Overflow用户

发布于 2012-10-10 12:45:14

您之所以会遇到这个问题,是因为您没有从意图获取值,必须有一个或多个值为null,或者您正在使用不同的键从意图获取值,请检查两个活动的键,它们是否相同。

票数 0
EN

Stack Overflow用户

发布于 2012-10-10 12:50:39

代码语言:javascript
复制
You are getting this error because.....

"This exception is thrown when a program attempts to create an URL from an
incorrect specification."
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12819394

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档