【发布时间】:2016-09-07 10:23:06
【问题描述】:
我的 Lyout 中有一个文本视图,我想在这个文本视图中设置一些文本。 这应该在不是 MainActivity 类的类中进行。
问题是我得到了一个空指针异常。
这是我的代码:
public class UserInformations extends Activity{
TextView emailTextView;
LocalDatabase localdatabase= new LocalDatabase(this);
public void getUserInformation()
{
emailTextView = (TextView) findViewById(R.id.EmailTextView);
String email = localdatabase.getUserEmail();
emailTextView.setText(email);
}
}
当我在 Main Activity 类中执行此操作时,它可以工作,但它在其他类中不起作用。
【问题讨论】:
-
emailTextView = (TextView) findViewById(R.id.EmailTextView);
-
不,我的数据库在另一个类中。电子邮件值很好,所以我认为问题出在 textView
标签: android android-view