package com.SoundEffect;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;
public class SoundEffectActivity extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery g = (Gallery) findViewById(R.id.gall1);
g.setAdapter(new ImageAdapter(this));
TextView T1 = (TextView) findViewById(R.id.T1);
T1.setOnClickListener(this);
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.a1,
R.drawable.a2,
R.drawable.a3,
R.drawable.a4,
R.drawable.a5,
R.drawable.beautifultarget
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(250, 150));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
public void onClick(View v) {
if(v.getId() == R.id.T1){
Intent intent = new Intent(SoundEffectActivity.this, rcm.class);
startActivity(intent);
}
}
}
package com.SoundEffect;
import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.TypedArray; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.TextView;
public class SoundEffectActivity extends Activity implements OnClickListener{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery g = (Gallery) findViewById(R.id.gall1);
g.setAdapter(new ImageAdapter(this));
TextView T1 = (TextView) findViewById(R.id.T1);
T1.setOnClickListener(this);
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.a1,
R.drawable.a2,
R.drawable.a3,
R.drawable.a4,
R.drawable.a5,
R.drawable.beautifultarget
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(250, 150));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
public void onClick(View v) {
if(v.getId() == R.id.T1){
Intent intent = new Intent(SoundEffectActivity.this, rcm.class);
startActivity(intent);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/T1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="23dip"
android:text="금주 추천곡" />
<Gallery
android:id="@+id/gall1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn1"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginLeft="23dip"
android:layout_marginTop="30dip"
android:drawableTop="@drawable/p1"
android:text="재생"
android:textSize="15dip" />
<Button
android:id="@+id/btn2"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginLeft="123dip"
android:layout_marginTop="-97dip"
android:drawableTop="@drawable/m1"
android:text="지역"
android:textSize="15dip" />
<Button
android:id="@+id/btn3"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginLeft="223dip"
android:layout_marginTop="-97dip"
android:drawableTop="@drawable/s1"
android:text="장르"
android:textSize="15dip" />
<Button
android:id="@+id/btn4"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginLeft="23dip"
android:layout_marginTop="30dip"
android:drawableTop="@drawable/st1"
android:text="공연"
android:textSize="15dip" />
<Button
android:id="@+id/btn5"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginLeft="123dip"
android:layout_marginTop="-97dip"
android:drawableTop="@drawable/r1"
android:text="추천"
android:textSize="15dip" />
<Button
android:id="@+id/btn6"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_marginLeft="223dip"
android:layout_marginTop="-97dip"
android:drawableTop="@drawable/stt1"
android:text="설정"
android:textSize="15dip" />
<LinearLayout
android:orientation="horizontal"
android:id="@+id/menu"
android:layout_width="fill_parent"
android:layout_marginTop="30dip"
android:layout_height="50dip">
<LinearLayout
android:id="@+id/menu01"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<Button
android:layout_width="105dip"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:textSize="23dip"
android:text="홈"/>
</LinearLayout>
<LinearLayout
android:id="@+id/menu02"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:layout_width="105dip"
android:layout_height="wrap_content"
android:textSize="23dip"
android:text="목록" />
</LinearLayout>
<LinearLayout
android:id="@+id/menu03"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<Button
android:layout_width="105dip"
android:layout_height="wrap_content"
android:textSize="23dip"
android:text="검색" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="23dip"
android:text="금주 추천곡" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="358dp" >
</ListView>
<LinearLayout
android:orientation="horizontal"
android:id="@+id/menu"
android:layout_width="fill_parent"
android:layout_marginTop="30dip"
android:layout_height="50dip">
<LinearLayout
android:id="@+id/m1"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<Button
android:layout_width="105dip"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:textSize="23dip"
android:text="홈"/>
</LinearLayout>
<LinearLayout
android:id="@+id/m2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:layout_width="105dip"
android:layout_height="wrap_content"
android:textSize="23dip"
android:text="목록" />
</LinearLayout>
<LinearLayout
android:id="@+id/m3"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<Button
android:layout_width="105dip"
android:layout_height="wrap_content"
android:textSize="23dip"
android:text="검색" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:padding="5dip">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
/>
</LinearLayout>
지금 프로그래밍 작성한거에서 나오는 로그캣입니다.
12-20 10:29:02.618: E/AndroidRuntime(339): FATAL EXCEPTION: main
12-20 10:29:02.618: E/AndroidRuntime(339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.SoundEffect/com.SoundEffect.rcm}: java.lang.ClassCastException: android.widget.TextView
12-20 10:29:02.618: E/AndroidRuntime(339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-20 10:29:02.618: E/AndroidRuntime(339): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-20 10:29:02.618: E/AndroidRuntime(339): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-20 10:29:02.618: E/AndroidRuntime(339): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-20 10:29:02.618: E/AndroidRuntime(339): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 10:29:02.618: E/AndroidRuntime(339): at android.os.Looper.loop(Looper.java:123)
12-20 10:29:02.618: E/AndroidRuntime(339): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-20 10:29:02.618: E/AndroidRuntime(339): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 10:29:02.618: E/AndroidRuntime(339): at java.lang.reflect.Method.invoke(Method.java:507)
12-20 10:29:02.618: E/AndroidRuntime(339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-20 10:29:02.618: E/AndroidRuntime(339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-20 10:29:02.618: E/AndroidRuntime(339): at dalvik.system.NativeStart.main(Native Method)
12-20 10:29:02.618: E/AndroidRuntime(339): Caused by: java.lang.ClassCastException: android.widget.TextView
12-20 10:29:02.618: E/AndroidRuntime(339): at com.SoundEffect.rcm.onCreate(rcm.java:37)
12-20 10:29:02.618: E/AndroidRuntime(339): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-20 10:29:02.618: E/AndroidRuntime(339): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
12-20 10:29:02.618: E/AndroidRuntime(339): ... 11 more
기본적인 레이아웃은 보입니다. 근데 텍스트뷰를 클릭하면 다른 액티비티로 전환 해주어야하는데 오류가 나서 이렇게 질문 올립니다.




rcm에서 37번째 줄에 TextView가 아닌 것을 TextView로 캐스팅 해주신 것 같네요. 근데 java파일 두개가 똑같은 소스 같은데.... 잘못올리신건 아닌가요??