强制关闭android中的错误
我是新来的android和我现在只开始。对于我当我试图实现点击应用程序关闭的按钮监听器。可以帮助任何人。强制关闭android中的错误
以下是代码:
public class Sampleprojectsubbu1Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button b1=(Button)findViewById(android.R.id.button1);
b1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
}
});
}
}
可能是在您遇到的错误这条线 -
final Button b1=(Button)findViewById(android.R.id.button1);
在上述行android.R.id.button1
将通过将与Android罐子来默认按钮提供。
而不是在那里,你必须使用按钮ID。你在main.xml
文件中使用了什么。就像如果您在使用的buttonconfirm
手段ID在你main.xml
一个按钮,你应该使用如下 -
final Button b1=(Button)findViewById(R.id.buttonconfirm);
希望这有助于你。并且,请在您的问题中发布您的main.xml
。
请更改此行。
final Button b1=(Button)findViewById(android.R.id.button1);
到
final Button b1=(Button)findViewById(R.id.button1);
由于all.Now其工作.. – subburaj 2012-04-24 05:54:40
您好我有一个问题,敬酒不apperingpublic无效的onClick(视图v) \t \t {\t \t \t \t的EditText的text1 =(EditText上)findViewById(R.id.editText1 ); \t \t \t \t \t \t \t \t // TODO自动生成方法存根 \t \t \t如果(text1.getText()。等于( “subbu”)) \t \t \t { \t \t \t \t Toast.makeText (Sampleprojectsubbu1Activity.this,“Hello”+ text1.getText(),Toast.LENGTH_LONG).show(); \t \t \t} \t \t \t \t } \t \t }); – subburaj 2012-04-24 06:12:00
你必须通过像addTextChangedListener这样的事件来处理这个事件。在这个实现'onTextChanged'方法。 – GAMA 2012-04-24 06:14:56
您正在使用的ID “android.R.id.button1”,这是Android的一部分,你应该使用类似R.id.your_button_id
你能发布logcat错误? – 2012-04-24 05:49:15
更改R.id.button1而不是android.R.id.button1。 – 2012-04-24 05:50:10
接受任何人对你满意的答案。 – Praveenkumar 2012-04-24 06:51:39