Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord,Intent)_Android - Fatal编程技术网

Android ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord,Intent)

Android ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord,Intent),android,Android,我在启动Intent时收到此错误。performLaunchActivity(ActivityThread$ActivityRecord,Intent)行:2585 public class SingleMenuItemActivity extends Activity { TextView lblName; TextView lblyest; TextView lbltoday; TextView lblHigh; TextView lblLow; TextView lblChange;

我在启动Intent时收到此错误。performLaunchActivity(ActivityThread$ActivityRecord,Intent)行:2585

public class SingleMenuItemActivity  extends Activity {

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

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);



      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");


      //Error doesnt happen when the lines below are commented
        lblName.setText((CharSequence)name.toString());
        lblyest.setText(yesterday.toString());
        lbltoday.setText(today.toString());
        lblHigh.setText(high.toString());
        lblLow.setText(low.toString());
        lblChange.setText(change.toString());
        lblPcchange.setText(pcchange.toString());  

}
}

我知道在执行settext()函数时会触发错误,但我不知道如何修复它,请尝试以下代码

public class SingleMenuItemActivity  extends Activity {

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

    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 );
        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 = (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 );

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

    }


}
实际上,在调用setContentView()之前不能初始化视图。这就是为什么您会遇到此问题。

请尝试此代码

public class SingleMenuItemActivity  extends Activity {

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

    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 );
        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 = (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 );

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

    }


}

实际上,在调用setContentView()之前不能初始化视图。这就是为什么会出现这个问题。

将这些行移到
setContentView(R.layout.single\u list\u item)之后


将这些行移动到
setContentView(R.layout.single_list_项)之后


您正在设置变量lblName和所有这些,以包含所有子视图的。。。但你是在课堂上做的。这些视图只有在布局膨胀后才会创建,在该行中
setContentView(R.layout.single_list_项)

,所以所有这些变量都被设置为null


在setContentView()调用后设置变量,然后查看其运行情况。

您正在设置变量lblName和所有这些变量,以包含子视图的所有。。。但你是在课堂上做的。这些视图只有在布局膨胀后才会创建,在该行中
setContentView(R.layout.single_list_项)

,所以所有这些变量都被设置为null


在setContentView()调用后设置变量,并查看其运行情况。

输入完整日志cat错误输入完整日志cat错误