开发者

Force Close when i run this application

开发者 https://www.devze.com 2023-01-29 21:43 出处:网络
I am new to programming. I\'m creating a simple app which will handle my Button click event. I have added the button using xml and linked it to the program, but the app force closes immediately after

I am new to programming. I'm creating a simple app which will handle my Button click event. I have added the button using xml and linked it to the program, but the app force closes immediately after I run it.

Here is the code:

public class Sparkling extends Activity implements OnClickListener 
{
    Button b;
    public void onCreate(Bundle savedInstanceState) 
    {开发者_运维知识库
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        b=(Button)findViewById(R.id.Button1);
        b.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) 
    {
        //actions....
    }
}


Without having any stack trace info, my guess would be Button1 is missing from or is misspelled on main.xml or something is wrong with your manifest file.


I found out what had happened.

I was using:

android:name="@+id/Button1"

instead of:

android:id="@+id/Button1"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号