Build Path Errors

by cdnyny » Mon, 14 Dec 2009 06:08:44 GMT


Sponsored Links
 When I try and run the canonical HelloWorld app, I get the following
error right after trying to create the project: "The project cannot be
built until build path errors are resolved". I tried Project/Clean and
the Window/Other Perspective/DDMS route, but to no avail. Closing and
restarting Eclipse did not solve the problem.

The SDK location is set as the folder that contains the "platforms"
sub-folder. I am running on XP, and have set the Target Name as
Android 2.0.1. I have tried deleting and redoing the entire procedure
a few times, but get this above error all the time. Any thoughts?

Thanks in advance.

--



Other Threads

1. How to style my own styleable with a style? (Custom view class with custom attribute)

If you are using attrs.getAttributeResourceValue(), then you are not using
the style/theming system at all.  That is, there was no purpose to defining
a <declare-styleable> an <attr> at all, that function is just retrieving a
raw value from a resource for a given name.  (This is also why the "
http://some.weird.url.com/seems/not/to/matter" URI doesn't matter -- you
have declared it as a namespace in your XML, and you have retrieved the
attribute in that namespace in your Java code, and that is all that is
happening.  You just made up a namespace and used it.)

You can find a complete example if declaring styleables and themes in API
demos.  Basically you declare a styleable like this (there is no "id" field
that is used):

<declare-styleable name="LabelView">
  <attr name="text" format="string"/>
  <attr name="textColor" format="color"/>
  <attr name="textSize" format="dimension"/>
  </declare-styleable>
</resources>

Then use it in a layout like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:app="http://schemas.android.com/apk/res/com.example.android.apis"

        android:orientation="vertical"
        android:layout_width="fill_parent"

        android:layout_height="wrap_content">

    <com.example.android.apis.view.LabelView

            android:background="@drawable/green"
            android:layout_width="fill_parent"

            android:layout_height="wrap_content"
            app:text="Green" app:textColor="#ffffffff" />

</LinearLayout>


Note that the URI of xmlns:app is very important, this is the namespace for
android resources (the first part) in your package (the second part).

Finally to retrieve the resources, you do this:

    public LabelView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initLabelView();

        TypedArray a = context.obtainStyledAttributes(attrs,

                R.styleable.LabelView);

        CharSequence s = a.getString(R.styleable.LabelView_text);
        if (s != null) {
            setText(s.toString());
        }

        // Retrieve the color(s) to be used for this view and apply them.

        // Note, if you only care about supporting a single color, that you
        // can instead call a.getColor() and pass that to setTextColor().
        setTextColor(a.getColor(R.styleable.LabelView_textColor, 0xFF000000));

        int textSize =
a.getDimensionPixelOffset(R.styleable.LabelView_textSize, 0);
        if (textSize > 0) {
            setTextSize(textSize);
        }

        a.recycle();
    }

The use of obtainedStyledAttributes() is very important, as that is the key
function that extracts the attributes you have declared in your styleable,
filling them in from the current AttributeSet or style or theme as
appropriate.

With all of that together, you can now define your theme, assigning values
to your own custom attributes that will be seen in your custom view.

On Wed, Jul 8, 2009 at 8:02 AM, brian.schim...@googlemail.com <





-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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.

--~--~---------~--~----~------------~-------~--~----~

2. How to style my own styleable with a style? (Custom view class with custom attribute)

Hi,

I'm creating my own View class, and defining custom xml attributes
with a attrs.xml. As long as I provide each attribute manually, there
is no problem, but

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <declare-styleable id="my.package.CustomizedButtonView"
name="CustomizedButtonView">
                <attr name="borderDrawable" format="reference|color"/>
        </declare-styleable>
</resources>

To be honest, I don't understand the proper use of the attributes "id"
and "name" in the above code, but somehow it works. I can now
reference the borderDrawable-Attribute from a layout xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:mypack="http://some.weird.url.com/seems/not/to/matter"

        <my.package.CustomizedButtonView
                                android:text="This is my text"
                                mypack:borderDrawable="@drawable/border243"/>
</LinearLayout>

My class CustomizedButtonView now reads the attribute like this:
        public CustomizedButtonView(Context context, AttributeSet attrs) {
                super(context, attrs);
                int borderDrawableId = attrs.getAttributeResourceValue(
                                "http://some.weird.url.com/seems/not/to/matter",
                                "borderDrawable", -1);

Until now, everything works fine. Many of my CustomizedButtonView will
have the same borderDrawable, but not all of them, so I want to define
a style. My styles.xml reads like this:

<style name="customStyle1">
                <item
                        name="android:text">Default text</item>
                <item
                        name="mypack:borderDrawable">@drawable/border243</item>
        </style>

And the layout like that:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:mypack="http://some.weird.url.com/seems/not/to/matter"

        <my.package.CustomizedButtonView
                                style="@style/customStyle1"/>
</LinearLayout>

The android:text is properly set in my instance, but the
borderDrawable is not. I guess this has something to do with
namespaces, because inside the styles.xml, the
name="mypack:borderDrawable" is not handled by the XML parser's
namespace facility, because its inside an attribute value. So "mypack"
is in no way connected to "http://some.weird.url.com/seems/not/to/
matter" and adding it via xmlns:mypack... to the stylefile would not
help, I guess. In the same file, "android:text" is somehow recognized,
even though "android" is AFAIK only a ns-defintion for "http://
schemas.android.com/apk/res/android", which is also not declared in
that file.

So what is the proper way to set a custom attribute in a style?
--~--~---------~--~----~------------~-------~--~----~

3. YUV to RGB cpnversion

4. TOUCHSCREEN ISSUE on SMDK2440 Platform

5. Launch another app through Android Application.

6. using appendChild and replaceChild

7. is it possible to get realtime gps values while not in a mapview?