틀림
package com.gusfree.gallery;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Gallery;

public class GalleryActivity extends Activity {
    Gallery gallery=null;
    int[] datas;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        gallery=(Gallery)this.findViewById(R.id.gallery1);      
        setContentView(R.layout.main);
        
        //nullPointException 발생 합니다.
        gallery.setBackgroundColor(Color.BLUE);        
        
    }
}




올바른 코드
package com.gusfree.gallery;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.Gallery;

public class GalleryActivity extends Activity {
    Gallery gallery=null;
    int[] datas;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.main);
        gallery=(Gallery)this.findViewById(R.id.gallery1);      
        
        gallery.setBackgroundColor(Color.BLUE);        
        
    }
}





틀린코드
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gusfree.gallery"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".GalleryActivity1"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


올바른 코드
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gusfree.gallery"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".GalleryActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


+ Recent posts