개요는 스플래시뷰 이후에 메인화면에서 버튼을 누르면 다른 뷰(FoodChoice.class)로 넘어가는 것을 구현할려고 합니다.

xml 파일에는 이상이 없습니다. id지정도 맞게 했구요.. 코드상에 오류는 없는데 실행하면 자동종료됩니다.

logcat 에 오류를 찾아보니 Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast

     to android.widget.Button

이라고 나오는데 여기서 어떻게 해야할지 모르겠네요. 답변 부탁드립니다^^


----> MainActivity.java


package com.devkim.choicemaster;


import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;


public class MainActivity extends Activity {

Button goFoodBtn, goWhoBtn, favoriteBtn, helpBtn, exitBtn;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

this.startActivity(new Intent(this, SplashView.class));

goFoodBtn = (Button) findViewById(R.id.goFoodBtn);

goFoodBtn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent intent = new Intent(getApplicationContext(), FoodChoice.class);

startActivity(intent);

}

});

}

}


----> SplashView.java


package com.devkim.choicemaster;


import android.annotation.SuppressLint;

import android.app.Activity;

import android.os.Bundle;

import android.os.Handler;

import android.os.Message;


public class SplashView extends Activity {


@SuppressLint("HandlerLeak")

@Override

public void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);

   setContentView(R.layout.splashview);

   

   Handler handler = new Handler() {

    public void handleMessage(Message msg) {

    finish();

    }

   };

   handler.sendEmptyMessageDelayed(0, 3000);

}

}


----> main.xml


<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/AbsoluteLayout1"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity"

    tools:ignore="Deprecated,HardcodedText" >


    <ImageView

        android:id="@+id/imageView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_x="0dp"

        android:layout_y="1dp"

        android:contentDescription="TODO"

        android:scaleType="fitXY"

        android:src="@drawable/main"

        tools:ignore="HardcodedText,ContentDescription" />


    <ImageView

        android:id="@+id/imageView3"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_x="0dp"

        android:layout_y="54dp"

        android:contentDescription="TODO"

        android:src="@drawable/main3"

        tools:ignore="HardcodedText,ContentDescription" />


    <ImageView

        android:id="@+id/imageView2"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_x="2dp"

        android:layout_y="27dp"

        android:src="@drawable/main2"

        tools:ignore="ContentDescription" />


    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="391dp"

        android:layout_x="1dp"

        android:layout_y="149dp"

        android:orientation="vertical" >


        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="60dp"

            android:layout_marginTop="75dp"

            android:contentDescription="TODO"

            tools:ignore="HardcodedText" >


            <ImageButton

                android:id="@+id/goFoodBtn"

                android:layout_width="104dp"

                android:layout_height="60dp"

                android:layout_marginLeft="35dp"

                android:layout_marginRight="35dp"

                android:contentDescription="TODO"

                android:src="@drawable/button1"

                tools:ignore="ContentDescription" />


            <ImageButton

                android:id="@+id/goWhoBtn"

                android:layout_width="104dp"

                android:layout_height="60dp"

                android:src="@drawable/button2"

                tools:ignore="ContentDescription" />


        </LinearLayout>


        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content" >


            <ImageButton

                android:id="@+id/favoriteBtn"

                android:layout_width="104dp"

                android:layout_height="60dp"

                android:layout_marginLeft="35dp"

                android:layout_marginRight="35dp"

                android:contentDescription="TODO"

                android:src="@drawable/button3"

                tools:ignore="ContentDescription" />


            <ImageButton

                android:id="@+id/helpBtn"

                android:layout_width="104dp"

                android:layout_height="60dp"

                android:src="@drawable/button4"

                tools:ignore="ContentDescription" />


        </LinearLayout>


        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content" >


            <ImageButton

                android:id="@+id/exitBtn"

                android:layout_width="104dp"

                android:layout_height="60dp"

                android:layout_marginLeft="108dp"

                android:src="@drawable/button5"

                tools:ignore="ContentDescription" />


        </LinearLayout>


    </LinearLayout>


</AbsoluteLayout>


----> splashview.xml


<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent" >


    <ImageView

        android:id="@+id/imageView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_x="0dp"

        android:layout_y="0dp"

        android:scaleType="fitXY"

        android:src="@drawable/main" />


    <TextView

        android:id="@+id/textView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_x="136dp"

        android:layout_y="263dp"

        android:text="Loading..."

        android:textColor="#FFFFFF" />


    <ProgressBar

        android:id="@+id/progressBar1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_x="138dp"

        android:layout_y="209dp" />


</AbsoluteLayout>