Reputation: 61
I'm studying android-development myself. When I use Gallery, there is a problem. Here is the code:
Gallery cf=new Gallery(this);
cf.setSpacing(20);
cf.setAdapter(imageAdapter);
cf.setAnimationDuration(1500);
setContentView(cf);
But when I try that, it's wrong.
Gallery cf=(Gallery)this.findViewById(R.id.Gallery);
cf.setSpacing(20);
cf.setAdapter(imageAdapter);
cf.setAnimationDuration(1500);
setContentView(R.layout.display);
<Gallery
android:id="@+id/Gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:spacing="-60px"/
>
What should I do?
EDIT: Logcat:
02-25 15:22:45.009: E/AndroidRuntime(500): FATAL EXCEPTION: main
02-25 15:22:45.009: E/AndroidRuntime(500): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vic.android.BluetoothContacts/com.vic.android.BluetoothContacts.PhotoDisplay}: java.lang.NullPointerException
02-25 15:22:45.009: E/AndroidRuntime(500): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-25 15:22:45.009: E/AndroidRuntime(500): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
Upvotes: 1
Views: 1300
Reputation: 9791
You are setContentView after findById - i think that's the problem Try
setContentView(R.layout.display);
Gallery cf=(Gallery)this.findViewById(R.id.Gallery);
cf.setSpacing(20);
cf.setAdapter(imageAdapter);
cf.setAnimationDuration(1500);
Upvotes: 1