Hi Kacper86,
  Thanks for your suggestion, I will make sure I provide more
completed code next time. And I actually figured out the problem.

The reason is because the auto-generated constructor (the one takes in
only one Context object) calls super() in its body, which seems to the
compiler that it will not initialize the final variable by any
chances.  The second constructor (the one takes in 2 parameters) calls
this() with 3 parameters, which leads the compiler to the third
constructor where the final variables are actually assigned some
value.

On Jul 22, 10:09 pm, Kacper86 <cpph...@gmail.com> wrote:
> Hi
>
> First of all, your code is a mess, and you shouldn't attach such
> snippets. Please be more careful, and make sure it'd be easy to read
> and compile. If it's not possible to compile then at least eliminate
> the most basic errors (e.g. mHandleId has no type, there is no class
> declaration etc.). Then, there is no "xxxxx" field in your code ;)
>
> Now, to the point. You can declare blank (without value) finals, but
> then all constructors MUST initialize it. This is a Java rule. So,
> either initialize it in all constructors, or remove the first two of
> them [constructors] if not needed.
>
> On Jul 22, 3:06 pm, nikki <nikki_...@pegatroncorp.com> wrote:
>
> > Hi
> >   I ran into a compiler error saying "The blank final field xxxxx may
> > not have been initialized" while I was extending ViewGroup to make
> > another UI thing by modifying SlidingDrawer.
>
> >   The fact is I'd already assigned some value to my final variable in
> > the 3rd constructor from ViewGroup, and I left the 1st and 2nd
> > constructors nothing but the auto-genned super()s.
>
> >   But for some reason this error only showed up at the 1st
> > constructor. And if I commented out the first constructor, the error
> > will just disappear instead of complaining about my empty 2nd
> > constructor.....
>
> >    I'm new to Java and Eclipse, so not sure if this is a Java or
> > Android thing, hope somebody stump upon here happens to have some
> > clue :)
>
> >    BTW my code:
> >     private final mHandleId;
> >     private final mContentId;
> >     public DeckView(Context context) {
> >         super(context);
> >         // TODO Auto-generated constructor stub
>
> >     }
>
> >     public DeckView(Context context, AttributeSet attrs) {
> >         this(context, attrs, 0);
> >     }
>
> >     public DeckView(Context context, AttributeSet attrs, int defStyle)
> > {
> >         super(context, attrs, defStyle);
> >         TypedArray a = context.obtainStyledAttributes
> > (attrs,R.styleable.DeckView,defStyle,0);
> >         int orientation = a.getInt
> > (R.styleable.SlidingDrawer_orientation, ORIENTATION_HORIZONTAL);
> >         mVertical = orientation == ORIENTATION_HORIZONTAL;
> >         mBottomOffset=(int)a.getDimension
> > (R.styleable.SlidingDrawer_bottomOffset, 0.0f);
> >         mTopOffset=(int)a.getDimension
> > (R.styleable.SlidingDrawer_topOffset,0.0f);
> >         mAllowSingleTap=a.getBoolean
> > (R.styleable.SlidingDrawer_allowSingleTap, true);
>
> >         int handleID = a.getResourceId
> > (R.styleable.SlidingDrawer_handle, 0);
> >         if(handleID == 0) {
> >             throw new IllegalArgumentException("The handle attribute
> > is required and must refer to a valid child");
> >         }
>
> >         int contentID = a.getResourceId
> > (R.styleable.SlidingDrawer_content, 0);
> >         if(contentID == 0) {
> >             throw new IllegalArgumentException("The content attribute
> > is requried and must refer to a valid child");
> >         }
>
> >         mHandleId = handleID;
> >         mContentId = contentID;
>
> >         a.recycle();
>
> >         setAlwaysDrawnWithCacheEnabled(false);
>
> >     }
>
> >    THANKS!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to