简体   繁体   中英

setText() not working

setText(), setTextsize() and addView is not working. It is shown as cannot resolve symbol type.

Intent intent = getIntent();
String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);

RelativeLayout layout = (RelativeLayout) findViewById(R.id.content);
layout.addView(textView);

You can't use methods such as add and find view by id before the layout is inflated. Verifý that setContentView is called before.

If it does, look at the value of message with a log.

Have you noticed this

``

At the end of this line

TextView textView = new TextView(this);``
Intent intent = getIntent();
String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);
TextView textView;
{
     textView = new TextView(this);
     textView.setTextSize(40);
     textView.setText(message);
}

RelativeLayout layout;
{
     layout = (RelativeLayout) findViewById(R.id.content);
     layout.addView(textView);
}

this solved my errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM