2017-11-29 20 views
-7

ボタンをクリックしてクラッシュすると新しいEditTextを作成したいのですが、その理由はわかりません。 (私はこれで非常に新しいです)アプリが起動しない

private Button addButton; 
private LinearLayout addLayout; 

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

    addButton = (Button) findViewById(R.id.button); 

    addButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      final LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT); 
      EditText editText = new EditText(getApplicationContext()); 
      editText.setLayoutParams(params); 
      addLayout.addView(editText); 


     } 
    }); 
} 

私は間違って何をしているのですか?

+0

は** addLayout **です – Prem

答えて

3

はあなたのaddLayout

この

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

    addButton = (Button) findViewById(R.id.button); 

    // bind your LinearLayout here 
    addLayout = (LinearLayout) findViewById(R.id.addLayout); 

    addButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      final LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT); 
      EditText editText = new EditText(getApplicationContext()); 
      editText.setLayoutParams(params); 
      addLayout.addView(editText); 


     } 
    }); 
} 
+0

おかげで男を試してみてくださいバインドするために忘れてしまいました!愚かな間違いXD – blokhunt

+0

@blokhuntあなたを助けてくれる – Prem

+0

@blokhuntあなたはこの記号を受け入れることができます – Prem

関連する問題