Thanks for the reply.

I've been looking into this some more, and it looks views must be
referenced from the thread in which they were inflated. Looks like I
should be interacting with views from the main thread, and using a
Handler object to interact with this thread from the worker thread.

On 17 May, 02:15, Dianne Hackborn <[email protected]> wrote:
> You probably shouldn't be doing this at all.  Certainly, you shouldn't be
> touching the view hierarchy from another thread.  I would expect what you
> are saying to actually work (and that you would get much more subtle
> errors), but it's hard to say without seeing the code and considering that
> there is a thread there running independently of the view hierarchy it is
> touching.
>
> On Sat, May 16, 2009 at 12:29 PM, steve_macleod
> <[email protected]>wrote:
>
>
>
>
>
>
>
> > OK, I have been looking into this some more, and it seems that the
> > reference to my ImageView is null.
> > My code is organised as follows:
>
> > Activity onCreate sets an onClick event
> > when the onClick event is activated, setContentView(layout_01) is
> > executed (this is the xml file which contains the ImageView) -  as
> > part of this xml file, a class which extends SurfaceView is inflated.
> > onCreate of this SurfaceView creates a thread (which is in inner
> > class) - that thread attempts to use the ImageView via findViewById,
> > which returns null.
>
> > Am I out-of-scope in attempting to reference the ImageView like this?
> > If so, how should I reference it?
>
> > Thanks,
>
> > On May 16, 4:38 pm, steve_macleod <[email protected]> wrote:
> > > Hi,
> > > I am attempting to animate an ImageView using frame-by-frame
> > > animation. I am using the following code:
>
> > > ImageView pacImageV = (ImageView) findViewById(R.id.pacAnim);
> > > pacImageV.setBackgroundResource(R.anim.pacanim);
> > > pacManCharAnim = (AnimationDrawable) pacImageV.getBackground();
>
> > > *********************************
>
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <FrameLayout xmlns:android="http://schemas.android.com/apk/res/
> > > android"
> > >     android:layout_width="fill_parent"
> > >     android:layout_height="fill_parent">
>
> > >     <android.pacman.com.PacManMainView
> > >       android:id="@+id/pacman_main_view"
> > >       android:layout_width="fill_parent"
> > >       android:layout_height="fill_parent"/>
>
> > >     <RelativeLayout
> > >         android:layout_width="fill_parent"
> > >         android:layout_height="fill_parent" >
>
> > >         <TextView
> > >           android:id="@+id/gamescreen_txt"
> > >                   android:text="@string/hello"
> > >                   android:visibility="visible"
> > >           android:layout_width="wrap_content"
> > >           android:layout_height="wrap_content"
> > >           android:layout_centerInParent="true"
> > >           android:gravity="center_horizontal"
> > >           android:textColor="#88ffffff"
> > >           android:textSize="24sp"
> > >           android:paddingTop="400px"/>
> > >      </RelativeLayout>
>
> > >      <ImageView
> > >         android:id="@+id/pacAnim"
> > >         android:layout_width="20px"
> > >         android:layout_height="20px"
> > >         android:scaleType="center"
> > >         android:src="@drawable/pac01"/>
>
> > > </FrameLayout>
>
> > > *********************************
>
> > > <animation-list xmlns:android="http://schemas.android.com/apk/res/
> > > android"
> > >     android:oneshot="true">
> > >     <item android:drawable="@drawable/pac01" android:duration="200" /
>
> > >     <item android:drawable="@drawable/pac02" android:duration="200" /
>
> > > </animation-list>
>
> > > *********************************
>
> > > Logcat shows a null pointer exception for the
> > > pacImageV.setBackgroundResource(R.anim.pacanim) line.
> > > Perhaps I am following the example incorrectly. I am using the 1.5
> > > sdk. Can anyone assist with this?
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.- 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