clojure-android / neko

The Clojure/Android Toolkit
Other
297 stars 36 forks source link

Unable to use drawable in :image-view #47

Closed ethagnawl closed 9 years ago

ethagnawl commented 9 years ago

I'm trying to use an image in an :image-view which lives in /res/drawable-*/dummy_image.png.

When I try to reference that image using android.R$drawable/dummy_image I see the following exception: Caused by: java.lang.RuntimeException: Unable to find static field: dummy_image in class android.R$drawable

alexander-yakushev commented 9 years ago

Well, looks like it doesn't have to do with :image-view, but the R class lacks that field. Can you check if target/debug/gen/<your-packaga/R.java has the necessary field?

ethagnawl commented 9 years ago

Here are the contents of R.java:

package org.stuff.events;

public final class R {
    public static final class anim {
        public static final int splash_rotation=0x7f040000;
    }
    public static final class attr {
    }
    public static final class drawable {
        public static final int dummy_image=0x7f020000;
        public static final int ic_launcher=0x7f020001;
        public static final int splash_background=0x7f020002;
        public static final int splash_circle=0x7f020003;
        public static final int splash_droid=0x7f020004;
        public static final int splash_hands=0x7f020005;
    }
    public static final class id {
        public static final int splash_app_name=0x7f060003;
        public static final int splash_circles=0x7f060001;
        public static final int splash_droid=0x7f060000;
        public static final int splash_droid_hands=0x7f060002;
    }
    public static final class layout {
        public static final int splashscreen=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f050000;
    }
}
alexander-yakushev commented 9 years ago

Sorry, I haven't read your original message carefully. You shouldn't use android.R class — that is a class that contains IDs of Android's own resources. Instead you should do the following:

;; First require neko.resource in your ns declaration

;; Immediately after (ns ..) add this line:
(neko.resource/import-all) ;; This will import all internal classes of your.package.name.R

R$drawable/dummy_image ;; This is the reference to your image
ethagnawl commented 9 years ago

Ah, ok - I guess that makes sense.

Unfortunately, I'm unable to require neko.resource. I've tried every variation of require and use that I'm familiar with, but the build always fails with No such var: neko.resource/import-all.

My apologies for the confusion, I'm still trying to wrap my head around the Java/Android ecosystem.

alexander-yakushev commented 9 years ago

You probably use the older version of Neko. The latest is 3.2.0-preview3.

Note that whenever you change the version of some dependency in your clojure-android project, it is a good idea to do lein clean before rebuilding.

ethagnawl commented 9 years ago

Upgrading to the latest Neko appears to have fixed my issue(s).

Thanks for your help! :)

alexander-yakushev commented 9 years ago

You are welcome!