Hi All,
I figured out the problem....the problem is with main.xml....
Earlier it was
<Gallery d="@+id/gallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
/>
i changed it to
this
<Gallery android:id="@+id/gallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
/>
this resolved the error...
Thanks
JavaAndroid

On Oct 17, 4:56 pm, JavaAndroid <[EMAIL PROTECTED]> wrote:
> Hi All,
> I tried displaying a small image in ContentView. But when i run the
> application It says ImageApplication closed unexpectedly....
>
> This is my Activity Class...
>
> public class ImageApplication extends Activity {
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle icicle) {
>         super.onCreate(icicle);
>         setContentView(R.layout.main);
>         ((Gallery) findViewById(R.id.gallery))
>                .setAdapter(new ImageAdapter(this));
>     }
>
> }
>
> And my Image Adapter class is this
> public class ImageAdapter extends BaseAdapter {
>     /** The parent context */
>        private Context myContext;
>
>        /** All images to be displayed.
>         * Put some images to project-folder:
>         * '/res/drawable/uvw.xyz' .*/
>        private int[] myImageIds = {
>               R.drawable.image1
>
>        };
>        /** Simple Constructor saving the 'parent' context. */
>        public ImageAdapter(Context c) { this.myContext = c; }
>
>        /** Returns the amount of images we have defined. */
>        public int getCount() { return this.myImageIds.length; }
>
>        /* Use the array-Positions as unique IDs */
>        public Object getItem(int position) { return position; }
>        public long getItemId(int position) { return position; }
>
>           /** Returns a new ImageView to
>      * be displayed, depending on
>      * the position passed. */
>     public View getView(int position, View convertView, ViewGroup
> parent) {
>         ImageView i = new ImageView(this.myContext);
>
>         i.setImageResource(this.myImageIds[position]);
>         /* Image should be scaled as width/height are set. */
>         i.setScaleType(ImageView.ScaleType.FIT_XY);
>         /* Set the Width/Height of the ImageView. */
>         i.setLayoutParams(new Gallery.LayoutParams(150, 150));
>         return i;
>     }
>
>     /** Returns the size (0.0f to 1.0f) of the views
>      * depending on the 'offset' to the center. */
>     public float getScale(boolean focused, int offset) {
>       /* Formula: 1 / (2 ^ offset) */
>         return Math.max(0, 1.0f / (float)Math.pow(2,
> Math.abs(offset)));
>     }
>
> }
>
> When i run the appliction i m getting this Exception in console...
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):
> java.lang.RuntimeException: Unable to start activity
> ComponentInfo{com.dreamapp.imageapplication.activity/
> com.dreamapp.imageapplication.activity.ImageApplication}:
> java.lang.NullPointerException
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
> 2140)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
> 2156)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> android.app.ActivityThread.access$1800(ActivityThread.java:112)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> android.os.Handler.dispatchMessage(Handler.java:88)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> android.os.Looper.loop(Looper.java:123)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> android.app.ActivityThread.main(ActivityThread.java:3742)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> java.lang.reflect.Method.invokeNative(Native Method)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> java.lang.reflect.Method.invoke(Method.java:515)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> com.android.internal.os.ZygoteInit
> $MethodAndArgsCaller.run(ZygoteInit.java:739)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> dalvik.system.NativeStart.main(Native Method)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203): Caused by:
> java.lang.NullPointerException
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> com.dreamapp.imageapplication.activity.ImageApplication.onCreate(ImageAppli­cation.java:
> 17)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
> 1122)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
> 2103)
> 10-17 17:14:09.864: ERROR/AndroidRuntime(203):     ... 11 more
>
> I have entry for id named gallery in main.xml. but it says
> NullPointerException at this line
> ((Gallery) findViewById(R.id.gallery))
>                .setAdapter(new ImageAdapter(this));
>
> Can anybody identify the error, i m stuck up with this for the past 2
> days......
>
> Thanks in Advance
>
> Thanks
> JavaAndroid
>
> On Oct 15, 11:55 am, JavaAndroid <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi Shailesh,
> > Thanks a lot for ur Help. Let me try that...Thanks again.
>
> > On Oct 15, 11:45 am, "shailesh prakash" <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
> > > you may like to try this 
> > > :http://code.google.com/p/apps-for-android/source/browse/trunk/Photost...
>
> > > On 10/15/08, JavaAndroid <[EMAIL PROTECTED]> wrote:
>
> > > > Hi All,
> > > > Can anyone direct me to some links / tutorials that will help me to
> > > > start experimenting on displaying images in Android . Is there any way
> > > > to add Servlet/JSP API in Android Application. Can i refer image that
> > > > is residing in a web server.
>
> > > > Thanks in Advance
>
> > > > Thanks
> > > > JavaAndroid- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to