How do you set a variable to an Edit Text Box
I'm new to android developing. I have a value in a variable that I need to set = to a edit text box. How do you do this? I keep getting a null exception error.
myStockPrice = (EditText)findViewById(R.id.txtStockPrice);
ManualPrice = input1.getText().toString().trim();
else if (ManualPrice != null)
{
myStockPrice.se开发者_运维技巧tText(ManualPrice);
}
Thanks
Hi try this may be in manualprice has no any value so you get a error :
myStockPrice = (EditText)findViewById(R.id.txtStockPrice);
ManualPrice = input1.getText().toString().trim();
else if (ManualPrice.length() > 0)
{
myStockPrice.setText(ManualPrice);
}
myStockPrice could be null because the edittext you are looking for is not in the layout you set with secContentView. is input1 a textview or an edittext? If so check if the belongs to the same layout you set with setContentView.. As others ask you, giving a bit of bt could better help to understand your problem
Assuming that input1
is not null, this should solve your problem,
myStockPrice = (EditText)findViewById(R.id.txtStockPrice);
ManualPrice = input1.getText().toString();
if (ManualPrice != null)
{
myStockPrice.setText(ManualPrice.trim());
}
精彩评论