06-20 02:39:06.807: E/AndroidRuntime(6652): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.noticekorea.mpm100/com.noticekorea.mpm100.MainActivity}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
06-20 02:39:06.807: E/AndroidRuntime(6652): Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
06-20 02:39:06.807: E/AndroidRuntime(6652): at com.noticekorea.mpm100.MainActivity.onCreate(MainActivity.java:52)
public class MainActivity extends Activity implements View.OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
// TODO Auto-generated method stub
getDate();
getTime();
loadGps();
getLocation();
Button btn2 = (Button)findViewById( R.id.save );
btn2.setOnClickListener( new Button.OnClickListener()
{
public void onClick(View arg0) {
// TODO Auto-generated method stub
showDialog(2);
}
});
}
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch(id)
{
case 1:
AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
builder2.setMessage("Want to Save really??");
builder2.setTitle("HEY");
//builder2.setView(View.inflate(this, R.layout.dlg1, null));
builder2.setIcon(R.drawable.ic_launcher);
builder2.setNegativeButton("CANCEL", null);
builder2.setPositiveButton("OK", null);
// 확인 버튼 클릭시 이벤트에 대한 처리부
builder2.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// 'YES'
dbSave();
}
}).setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// 'No'
}
});
return builder2.create();
}
return null;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
case R.id.view :
Intent intent = new Intent(MainActivity.this, DataActivity.class);
//startActivityForResult(intent, 0); //값을 전달 다시 받아오기 위해 forResult를 사용
startActivity(intent);
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:background="@drawable/save_btn"
android:onClick="onClick"
/>
<ImageButton
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:background="@drawable/main_btn"
android:onClick="onClick"/>
</RelativeLayout>