Reputation: 435
userString=(EditText)findViewById(R.id.letter);
checkButton=(Button)findViewById(R.id.go);
text=(TextView)findViewById(R.id.display);
checkButton.setOnClickListener(new View.OnClickListener(){
@SuppressWarnings("null")
public void onClick(View v){
char answer[]=null;int i;
String userEntry=userString.getText().toString();
for(i=0;i<userEntry.length();i++)
{
answer[i]='_';
}
text.setText(answer, 0, i);
}
}});
When I run the above code it says"The Application has stopped unexpectedly.Please Try again".How do i solve this? Thanks
Upvotes: 2
Views: 2077
Reputation: 2541
you are trying to place items (characters) into an array that has not been allocated. you need something like
char answer[] = new char[size];
at some point prior to placing characters into it.
Upvotes: 3