1

Running into a slight Inflation issue while trying to implement the micode open source compass into my app. So I am trying to figure out how to fix this. Another set of eyes looking at this would be good. So here we go:

Here is the class that this is relating to:

package styckz.com.clearpicturemode;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;

public class CompassView extends ImageView {
private float mDirection;
private Drawable compass;

public CompassView(Context context) {
    super(context);
    mDirection = 0.0f;
    compass = null;
}

public CompassView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mDirection = 0.0f;
    compass = null;
}

public CompassView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mDirection = 0.0f;
    compass = null;
}

@Override
protected void onDraw(Canvas canvas) {
    if (compass == null) {
        compass = getDrawable();
        compass.setBounds(0, 0, getWidth(), getHeight());
    }

    canvas.save();
    canvas.rotate(mDirection, getWidth() / 2, getHeight() / 2);
    compass.draw(canvas);
    canvas.restore();
}

public void updateDirection(float direction) {
    mDirection = direction;
    invalidate();
}

}

So here we are... I tried turning that class above from public to static to no avail as per the request in another thread and it did not work... Maybe I am doing something wrong? All that did was make the class name highlight red below it and claim that static was invalid.

Any ideas?

Here is the Layout XML file:

<?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" >

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background" >

    <LinearLayout
        android:id="@+id/view_compass"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/background_light"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:orientation="vertical" >

            <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/prompt" >

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginTop="70dip"
                    android:orientation="horizontal" >

                    <LinearLayout
                        android:id="@+id/layout_direction"
                        android:layout_width="0dip"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="right"
                        android:orientation="horizontal" >
                    </LinearLayout>

                    <ImageView
                        android:layout_width="20dip"
                        android:layout_height="fill_parent" >
                    </ImageView>

                    <LinearLayout
                        android:id="@+id/layout_angle"
                        android:layout_width="0dip"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="left"
                        android:orientation="horizontal" >
                    </LinearLayout>
                </LinearLayout>
            </FrameLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dip"
                android:layout_weight="1"
                android:orientation="vertical" >

                <FrameLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center" >

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:src="@drawable/background_compass" />

                    <net.micode.compass.CompassView
                        android:id="@+id/compass_pointer"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:src="@drawable/compass" />

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:src="@drawable/miui_cover" />
                </FrameLayout>
            </LinearLayout>
        </LinearLayout>

        <FrameLayout
            android:id="@+id/location_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/background_bottom"
                android:orientation="vertical" >
            </LinearLayout>

            <TextView
                android:id="@+id/textview_location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/getting_location"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#7FFFFFFF" />
        </FrameLayout>
    </LinearLayout>
</FrameLayout>

<include
    android:id="@+id/low_accuracy_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginBottom="35dip"
    layout="@*android:layout/transient_notification"
    android:visibility="gone" />

Also here is the logcat of doom:

11-22 14:22:30.667: E/AndroidRuntime(16140): FATAL EXCEPTION: main
11-22 14:22:30.667: E/AndroidRuntime(16140): java.lang.RuntimeException: Unable to start     activity        ComponentInfo{styckz.com.clearpicturemode/styckz.com.clearpicturemode.CompassActivity}:   android.view.InflateException: Binary XML file line #94: Error inflating class  net.micode.compass.CompassView
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.os.Looper.loop(Looper.java:137)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.app.ActivityThread.main(ActivityThread.java:5103)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at java.lang.reflect.Method.invokeNative(Native Method)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at java.lang.reflect.Method.invoke(Method.java:525)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at dalvik.system.NativeStart.main(Native Method)
11-22 14:22:30.667: E/AndroidRuntime(16140): Caused by: android.view.InflateException: Binary XML file line #94: Error inflating class net.micode.compass.CompassView
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.app.Activity.setContentView(Activity.java:1895)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at styckz.com.clearpicturemode.CompassActivity.onCreate(CompassActivity.java:99)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.app.Activity.performCreate(Activity.java:5133)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-22 14:22:30.667: E/AndroidRuntime(16140):    ... 11 more
11-22 14:22:30.667: E/AndroidRuntime(16140): Caused by: java.lang.ClassNotFoundException: Didn't find class "net.micode.compass.CompassView" on path: DexPathList[[zip file "/data/app/styckz.com.clearpicturemode-2.apk"],nativeLibraryDirectories=[/data/app-lib/styckz.com.clearpicturemode-2, /vendor/lib, /system/lib]]
11-22 14:22:30.667: E/AndroidRuntime(16140):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.createView(LayoutInflater.java:559)
11-22 14:22:30.667: E/AndroidRuntime(16140):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
11-22 14:22:30.667: E/AndroidRuntime(16140):    ... 26 more
6
  • You need to post your xml file as the problem is there. Commented Nov 22, 2013 at 20:35
  • Alright, sorry about that! Commented Nov 22, 2013 at 20:36
  • 1
    by the error it appears you may have your paths mixed up as it is looking for CompasView in net.micode.compass.CompassView where you have compasview in styckz.com.clearpicturemode Commented Nov 22, 2013 at 20:36
  • I added the layout @Szymon | Alright how do I go about changing that @tyczj? Commented Nov 22, 2013 at 20:39
  • probably a library inclusion issue. Commented Nov 22, 2013 at 20:40

1 Answer 1

1

the problem is you have the wrong path in your xml.

you have CompassView as being located in net.micode.compass. but it is actually located in styckz.com.clearpicturemode

so change that in your xml

this

<net.micode.compass.CompassView
   android:id="@+id/compass_pointer"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:src="@drawable/compass" />

should look like this

<styckz.com.clearpicturemode.CompassView
   android:id="@+id/compass_pointer"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:src="@drawable/compass" />
Sign up to request clarification or add additional context in comments.

1 Comment

Alright now I need to find this transient notification thing in the include section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.