Android应用崩溃

时间:2012-06-21 12:58:08

标签: android

为什么:

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

导致程序崩溃? 我已经广泛地查看了代码,我无法将其放在上面,调试器也会在打开新的页面选项卡时告诉我发生了什么事情时说未找到源代码。

1 个答案:

答案 0 :(得分:1)

先尝试拨打setContentView(helpLayout);,然后再buttonCreator();

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);

    setContentView(helpLayout);
   buttonCreator();
}

假设你试图在你的helplayout中声明的按钮中初始化buttonCreater()内的按钮,你可能会遇到Null Pointer Exception。