如何将textView setText从onCreate中删除?

时间:2017-04-25 14:45:28

标签: java android swing mobile text

import com.example.zulkuf.sdukampus.fragments.DayKey;

/**
 * Created by zulkuf on 24.4.2017.
 */    
public class BusItemClickActivity extends AppCompatActivity{

    private ImageView imClick;
    public TextView tv1Click, tv2Click, tv3Click;
    private String busClickTime;
    private String busClickNumber;
    private String busClickRoute;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bus_item_click_activity);

        imClick = (ImageView) findViewById(R.id.ivBusClickNumberImage);
        tv1Click = (TextView) findViewById(R.id.tvBusClickNumber);
        tv2Click = (TextView) findViewById(R.id.BusClickTime);
        tv3Click = (TextView) findViewById(R.id.BusClickRoute);
    }

    public void busInformation(String[] info){
         busClickNumber = info[0].toString();
        busClickTime = info[1].toString();
        busClickRoute = info[2].toString();

        tv1Click.setText(busClickNumber);
        tv2Click.setText(busClickTime);
        tv3Click.setText(busClickRoute);   
    }
}

1 个答案:

答案 0 :(得分:0)

从您的评论/回答中,似乎其中一个findViewById正在返回null。当找不到视图时会发生这种情况。确保布局文件中的id与java代码中的id相同。