마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

unfortunately has stopped 에러가 나네요

0 추천
JAVA 코드
package com.example.second_doit;

import com.example.second_doit.R;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ScrollView;

public class MainActivity extends Activity {
	
	ScrollView scrollView01;
	ImageView imageView01;
	ImageView imageView02;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        scrollView01=(ScrollView) findViewById(R.id.scrollView01);
        imageView01=(ImageView) findViewById(R.id.imageView01);
        imageView02=(ImageView) findViewById(R.id.imageView02);
        Button button01 = (Button) findViewById(R.id.button01);
        
        scrollView01.setHorizontalScrollBarEnabled(true);
        
        
        Resources res=getResources();
        BitmapDrawable bitmap = (BitmapDrawable) res.getDrawable(R.drawable.first);
        int bitmapWidth = bitmap.getIntrinsicWidth();
        int bitmapHeight = bitmap.getIntrinsicHeight();
        
        imageView01.setImageDrawable(bitmap);
        imageView01.getLayoutParams().width=bitmapWidth;
        imageView01.getLayoutParams().height=bitmapHeight;
        
        button01.setOnClickListener(new OnClickListener(){
        	public void onClick(View v){
        		changeImage();
        	}
        });
        
        
    }


    private void changeImage(){
    	int imageIndex=0;
    	if(imageIndex==0){
    		imageView01.setVisibility(View.VISIBLE);
    		imageView02.setVisibility(View.INVISIBLE);
    			imageIndex=1;
    	}
    	else if(imageIndex==1){
    		imageView01.setVisibility(View.INVISIBLE);
    		imageView02.setVisibility(View.VISIBLE);
    		
    		imageIndex=0;
    	}
    }
   
}

activity XML코드
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

<HorizontalScrollView
    android:id="@+id/horScrollView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <ScrollView
        android:id="@+id/scrollView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <ImageView
            android:id="@+id/imageView01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/first"
            />
        
			<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="10dp"
    >
    
    <Button
        android:id="@+id/button01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        />
    <Button
        android:id="@+id/button02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        />   
			
			</LinearLayout>
			
	<Imageview
	    android:id="@+id/imageView02"
	    android:layout_width="wrap_content"
	    android:layout_height="wrap_content"
	    android:src="@drawable/first"
	    />
		</ScrollView>
	</HorizontalScrollView>
</RelativeLayout>

RUN 시키면

Unfortunately  has stopped 라고 뜨네요 ㅜㅜ

spock (250 포인트) 님이 2014년 3월 10일 질문

2개의 답변

+3 추천

Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child

익명사용자 님이 2014년 3월 10일 답변
0 추천

로그캣은 다음과 같습니당

03-10 00:25:17.730: D/dalvikvm(943): GC_FOR_ALLOC freed 47K, 4% free 3136K/3252K, paused 178ms, total 180ms
03-10 00:25:17.800: I/dalvikvm-heap(943): Grow heap (frag case) to 4.198MB for 1127536-byte allocation
03-10 00:25:17.950: D/dalvikvm(943): GC_FOR_ALLOC freed 2K, 3% free 4235K/4356K, paused 153ms, total 153ms
03-10 00:25:18.100: D/dalvikvm(943): GC_FOR_ALLOC freed <1K, 3% free 4243K/4356K, paused 23ms, total 23ms
03-10 00:25:18.110: I/dalvikvm-heap(943): Grow heap (frag case) to 4.896MB for 726640-byte allocation
03-10 00:25:18.230: D/dalvikvm(943): GC_FOR_ALLOC freed <1K, 3% free 4952K/5068K, paused 104ms, total 104ms
03-10 00:25:18.290: D/AndroidRuntime(943): Shutting down VM
03-10 00:25:18.290: W/dalvikvm(943): threadid=1: thread exiting with uncaught exception (group=0xb1ad5ba8)
03-10 00:25:18.320: E/AndroidRuntime(943): FATAL EXCEPTION: main
03-10 00:25:18.320: E/AndroidRuntime(943): Process: com.example.second_doit, PID: 943
03-10 00:25:18.320: E/AndroidRuntime(943): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.second_doit/com.example.second_doit.MainActivity}: java.lang.IllegalStateException: ScrollView can host only one direct child
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.os.Handler.dispatchMessage(Handler.java:102)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.os.Looper.loop(Looper.java:136)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.app.ActivityThread.main(ActivityThread.java:5017)
03-10 00:25:18.320: E/AndroidRuntime(943):  at java.lang.reflect.Method.invokeNative(Native Method)
03-10 00:25:18.320: E/AndroidRuntime(943):  at java.lang.reflect.Method.invoke(Method.java:515)
03-10 00:25:18.320: E/AndroidRuntime(943):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-10 00:25:18.320: E/AndroidRuntime(943):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-10 00:25:18.320: E/AndroidRuntime(943):  at dalvik.system.NativeStart.main(Native Method)
03-10 00:25:18.320: E/AndroidRuntime(943): Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.widget.ScrollView.addView(ScrollView.java:255)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-10 00:25:18.320: E/AndroidRuntime(943):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.app.Activity.setContentView(Activity.java:1929)
03-10 00:25:18.320: E/AndroidRuntime(943):  at com.example.second_doit.MainActivity.onCreate(MainActivity.java:23)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.app.Activity.performCreate(Activity.java:5231)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-10 00:25:18.320: E/AndroidRuntime(943):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-10 00:25:18.320: E/AndroidRuntime(943):  ... 11 more
03-10 00:25:23.980: I/Process(943): Sending signal. PID: 943 SIG: 9
03-10 00:26:37.481: D/dalvikvm(1153): GC_FOR_ALLOC freed 39K, 4% free 3136K/3244K, paused 95ms, total 96ms
03-10 00:26:37.491: I/dalvikvm-heap(1153): Grow heap (frag case) to 4.198MB for 1127536-byte allocation
03-10 00:26:37.701: D/dalvikvm(1153): GC_FOR_ALLOC freed 2K, 3% free 4235K/4348K, paused 142ms, total 142ms
 
spock (250 포인트) 님이 2014년 3월 10일 답변
03-10 00:26:37.791: D/dalvikvm(1153): GC_FOR_ALLOC freed <1K, 3% free 4243K/4348K, paused 22ms, total 23ms
03-10 00:26:37.801: I/dalvikvm-heap(1153): Grow heap (frag case) to 4.896MB for 726640-byte allocation
03-10 00:26:37.841: D/dalvikvm(1153): GC_FOR_ALLOC freed <1K, 3% free 4953K/5060K, paused 39ms, total 39ms
03-10 00:26:37.921: D/AndroidRuntime(1153): Shutting down VM
03-10 00:26:37.921: W/dalvikvm(1153): threadid=1: thread exiting with uncaught exception (group=0xb1ad5ba8)
03-10 00:26:37.931: E/AndroidRuntime(1153): FATAL EXCEPTION: main
03-10 00:26:37.931: E/AndroidRuntime(1153): Process: com.example.second_doit, PID: 1153
03-10 00:26:37.931: E/AndroidRuntime(1153): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.second_doit/com.example.second_doit.MainActivity}: java.lang.IllegalStateException: ScrollView can host only one direct child
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.os.Handler.dispatchMessage(Handler.java:102)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.os.Looper.loop(Looper.java:136)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.app.ActivityThread.main(ActivityThread.java:5017)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at java.lang.reflect.Method.invokeNative(Native Method)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at java.lang.reflect.Method.invoke(Method.java:515)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at dalvik.system.NativeStart.main(Native Method)
03-10 00:26:37.931: E/AndroidRuntime(1153): Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.widget.ScrollView.addView(ScrollView.java:255)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.app.Activity.setContentView(Activity.java:1929)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at com.example.second_doit.MainActivity.onCreate(MainActivity.java:23)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.app.Activity.performCreate(Activity.java:5231)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-10 00:26:37.931: E/AndroidRuntime(1153):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-10 00:26:37.931: E/AndroidRuntime(1153):  ... 11 more


도와주세요 ㅠㅠ 할때마다 계속 막히니까 너무 힘드네여 ㅠㅠ 이겨내야겟죠??
...