为什么:
public class HelpTab extends Activity
{
LinearLayout helpLayout; //was changed to LinearLayout helpLayout = new LinearLayout(this);
TextView helpText = new TextView(this);
Button tips = new Button(this);
Button walkThrough = new Button(this);
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
buttonCreator();
setContentView(helpLayout);
}
public void buttonCreator()
{
//Button featuress defined in here (setText("") and adding them to the layout, addView();)
}
导致程序崩溃? 我已经广泛地查看了代码,我无法将其放在上面,调试器也会在打开新的页面选项卡时告诉我发生了什么事情时说未找到源代码。
答案 0 :(得分:1)
先尝试拨打setContentView(helpLayout);
,然后再buttonCreator();
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(helpLayout);
buttonCreator();
}
假设你试图在你的helplayout
中声明的按钮中初始化buttonCreater()内的按钮,你可能会遇到Null Pointer Exception。