Application ... stopped unexpectedly

Quickly share your Android Code Snippets here...

Application ... stopped unexpectedly

Postby rosebeat » Tue Sep 14, 2010 9:10 am

When I run this code, I get the android error as "Application... has stopped unexpectedly. There is no error with the code. May be I ma missing something here. Can anyone help me out...?


Here is my Java code


package org.me.androidapplication28;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class Message extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
Button alert=(Button) findViewById(R.id.alert);
alert.setOnClickListener((View.OnClickListener) this);

}
public void OnClick(View view)
{
if(view==findViewById(R.id.alert))
{
AlertDialog.Builder alertbox=new AlertDialog.Builder(this);
alertbox.setMessage("Are you sure you want to exit?");
alertbox.setPositiveButton("Yes",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface arg0, int arg1)
{
Toast.makeText(getApplicationContext(), " ' Yes' button clicked" , Toast.LENGTH_SHORT).show();
}
});
//set negative button
alertbox.setNegativeButton("No",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface arg0,int arg1)
{
Toast.makeText(getApplicationContext(),"'No' button clicked",Toast.LENGTH_SHORT).show();
}
}
);
alertbox.show();
}

}
}

Here is the xml code...
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">"
<Button
android:id="@+id/alert"
android:text="Are you sure you want to exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

</LinearLayout>
rosebeat
Junior Developer
Junior Developer
 
Posts: 15
Joined: Wed Sep 08, 2010 6:06 am

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 3 guests