充气课时出错?

时间:2014-11-04 07:31:05

标签: java android eclipse

我将项目从Eclipse迁移到Android Studio。在我的项目中,我添加了this library。 我已将库添加为gradle文件中的依赖项。我可以从我的班级导入库。
但它显示了这个

android.view.InflateException: Binary XML file line #8: Error inflating class com.digitalaria.gama.wheel.Wheel

运行应用程序时

注意 - 从Eclipse运行它时工作正常。

gradle这个

apply plugin: 'android'

dependencies {
    //    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':RemoteIt Protocol')
    compile project(':android-support-v7-appcompat')
    compile files('libs/gama_wheel_v1.0.jar')
    compile files('libs/PayPalAndroidSDK.jar')
}

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')
            debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >

 <com.digitalaria.gama.wheel.Wheel
        android:id="@+id/wheel"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </com.digitalaria.gama.wheel.Wheel>

</LinearLayout>

import com.digitalaria.gama.wheel.Wheel;
import com.digitalaria.gama.wheel.WheelAdapter;

public class Home extends MainActivity implements OnClickListener
{
    private RemoteIt application;
    private SharedPreferences preferences;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        this.application = (RemoteIt) this.getApplication();
        this.preferences = this.application.getPreferences();
        super.onCreate(savedInstanceState);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle(s);
        this.checkOnCreate();

        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentView = inflater.inflate(R.layout.home, null, false);
        mDrawer.addView(contentView, 0);
        init();
        wheel();
    }

    private void wheel()
    {
        wheel.setOnItemClickListener(new WheelAdapter.OnItemClickListener()
        {
            @Override
            public void onItemClick(WheelAdapter<?> parent, View view, int position, long id)
            {
                switch (position)
                {
                    case 0:
                        Intent ac = new Intent(Home.this, ConnectionListActivity.class);
                        startActivity(ac);
                        break;
                    case 1:
                        Intent b = new Intent(Home.this, ControlActivity.class);
                        startActivity(b);
                        break;
                    case 2:
                        Intent c = new Intent(Home.this, FileExplorerActivity.class);
                        startActivity(c);
                        // this.toggleKeyboard();
                        break;
                    case 3:
                        Intent d = new Intent(Home.this, Presentation.class);
                        startActivity(d);
                        break;
                    case 4:
                        Intent e = new Intent(Home.this, Media.class);
                        startActivity(e);
                        break;
                    case 5:
                        Intent f = new Intent(Home.this, Shortcuts.class);
                        startActivity(f);
                        break;
                    case 6:
                        Intent g = new Intent(Home.this, Browser.class);
                        startActivity(g);
                        break;
                }
            }
        });
    }

    private Wheel wheel;
    private Resources res;
    private int[] icons = {
            R.drawable.conn, R.drawable.mouse, R.drawable.file, R.drawable.present, R.drawable.media, R.drawable.shortc, R.drawable.browser
    };

    private void init()
    {
        res = getApplicationContext().getResources();
        wheel = (Wheel) findViewById(R.id.wheel);
        wheel.setItems(getDrawableFromData(icons));
        wheel.setWheelDiameter((int) getResources().getDimension(R.dimen.diameter));
    }

    private Drawable[] getDrawableFromData(int[] data)
    {
        Drawable[] ret = new Drawable[data.length];
        for (int i = 0; i < data.length; i++)
        {
            ret[i] = res.getDrawable(data[i]);
        }
        return ret;
    }

logcat的

 Process: com.RemoteIt.client, PID: 1825
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.RemoteIt.client/com.RemoteIt.client.activity.Home}: android.view.InflateException: Binary XML file line #8: Error inflating class com.digitalaria.gama.wheel.Wheel
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.digitalaria.gama.wheel.Wheel
            at android.view.LayoutInflater.createView(LayoutInflater.java:620)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at com.RemoteIt.client.activity.Home.onCreate(Home.java:50)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                at android.app.ActivityThread.access$800(ActivityThread.java:135)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:136)
                at android.app.ActivityThread.main(ActivityThread.java:5001)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                at com.RemoteIt.client.activity.Home.onCreate(Home.java:50)
                at android.app.Activity.performCreate(Activity.java:5231)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                at android.app.ActivityThread.access$800(ActivityThread.java:135)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:136)
                at android.app.ActivityThread.main(ActivityThread.java:5001)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3
            at android.content.res.TypedArray.getInteger(TypedArray.java:368)
            at com.digitalaria.gama.wheel.WheelBehavior.<init>(WheelBehavior.java:117)
            at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:83)
            at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:68)
                at java.lang.reflect.Constructor.constructNative(Native Method)
                at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
                at android.view.LayoutInflater.createView(LayoutInflater.java:594)
                at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
                at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                at com.RemoteIt.client.activity.Home.onCreate(Home.java:50)
                at android.app.Activity.performCreate(Activity.java:5231)
                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                at android.app.ActivityThread.access$800(ActivityThread.java:135)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                at android.os.Handler.dispatchMessage(Handler.java:102)
                at android.os.Looper.loop(Looper.java:136)
                at android.app.ActivityThread.main(ActivityThread.java:5001)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                at dalvik.system.NativeStart.main(Native Method)

Wheel.java

public final class Wheel extends android.widget.FrameLayout {
    public static final int CCW = -1;
    public static final int CW = 1;
    private com.digitalaria.gama.wheel.WheelBehavior _wheelBehavior;
    private android.view.ViewStub _backgroundViewDummy;
    protected android.view.View _backgroundView;
    protected boolean _hasBackgroundImage;
    private android.widget.FrameLayout.LayoutParams params;
    private int _reservedPositionLeft;
    private int _reservedPositionTop;
    private boolean isLayout;
    private int _storedLeft;
    private int _storedTop;
    private int _storedRight;
    private int _storedBottom;
    private int _centerX;
    private int _centerY;

    public Wheel(android.content.Context context) { /* compiled code */ }

    public Wheel(android.content.Context context, android.util.AttributeSet attrs) { /* compiled code */ }

    public Wheel(android.content.Context context, android.util.AttributeSet attrs, int defStyle) { /* compiled code */ }

    protected void onLayout(boolean changed, int l, int t, int r, int b) { /* compiled code */ }

    public void addView(android.view.View child) { /* compiled code */ }

    public void addView(android.view.View child, int index) { /* compiled code */ }

    public void removeView(android.view.View child) { /* compiled code */ }

    public void removeViewAt(int index) { /* compiled code */ }

    public float getCenterX() { /* compiled code */ }

    public float getCenterY() { /* compiled code */ }

    public final void setOnItemClickListener(com.digitalaria.gama.wheel.WheelAdapter.OnItemClickListener listener) { /* compiled code */ }

    public final com.digitalaria.gama.wheel.WheelAdapter.OnItemClickListener getOnItemClickListener() { /* compiled code */ }

    public final void setOnWheelRotationListener(com.digitalaria.gama.wheel.WheelAdapter.OnWheelRotationListener listener) { /* compiled code */ }

    public final com.digitalaria.gama.wheel.WheelAdapter.OnWheelRotationListener getOnWheelRotationListener() { /* compiled code */ }

    public void setOnItemSelectionUpdatedListener(com.digitalaria.gama.wheel.WheelAdapter.OnItemSelectionUpdatedListener listener) { /* compiled code */ }

    public void setPosition(int left, int top) { /* compiled code */ }

    public void setSelectionAngle(int angle) { /* compiled code */ }

    public void setItems(android.content.res.TypedArray items) { /* compiled code */ }

    public void setItems(android.graphics.drawable.Drawable[] drawables) { /* compiled code */ }

    public void setWheelDiameter(int diameter) { /* compiled code */ }

    public void setWheelBackground(int inflatedId, int layoutResource) { /* compiled code */ }

    public void setRotatedItem(boolean flag) { /* compiled code */ }

    public void configureWheelBackground(int initRotationAngle, boolean rotatedItem) { /* compiled code */ }

    public void configureWheelBackground(boolean rotatedItem) { /* compiled code */ }

    protected boolean hasBackgroundImage() { /* compiled code */ }

    public void setTouchArea(int from, int to) { /* compiled code */ }

    public int nextItem() { /* compiled code */ }

    public int previousItem() { /* compiled code */ }

    public boolean isRotationFinished() { /* compiled code */ }

    public void flingStartUsingAngle(float angle) { /* compiled code */ }

    public void flingStartUsingVelocity(int vx, int vy, boolean scroolToSlot) { /* compiled code */ }

    public void flingStartUsingVelocityWithDirection(int vx, int vy, int direction) { /* compiled code */ }

    public int getSelectedItem() { /* compiled code */ }

    public int getSelectedItem(boolean stopScroll) { /* compiled code */ }

    public boolean setSelectedItem(int index) { /* compiled code */ }

    public void setItemClickEventAtSelectionPosition(boolean enable) { /* compiled code */ }

    public boolean getItemClickEventAtSelectionPosition() { /* compiled code */ }

    public void setEnabled(boolean enabled) { /* compiled code */ }

    public boolean isLayouted() { /* compiled code */ }
}

4 个答案:

答案 0 :(得分:2)

相关例外:

Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3
at android.content.res.TypedArray.getInteger(TypedArray.java:368)
at com.digitalaria.gama.wheel.WheelBehavior.<init>(WheelBehavior.java:117)

WheelBehavior.java,第117行

setWheelDiameter(arr.getInteger(R.styleable.Wheel_wheel_diameter, Configuration.DEFAULT_WHEEL_DIAMETER));

以下是可设置的属性:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="Wheel">
        <attr name="wheel_rotation_duration" format="integer"/> <!-- default:400 -->
        <attr name="wheel_diameter" format="integer"/> <!-- default:250 -->
        <attr name="items" format="integer"/>
        <attr name="item_selected_index" format="integer"/>
    </declare-styleable>
</resources>
必须在项目的某个地方定义

wheel_diameter,而不是在其中包含整数。这就是崩溃的原因。但根据你的布局,它不是。尝试对字符串wheel_diameter

进行全局搜索

答案 1 :(得分:0)

我认为我的回答是狂野的,但您可以尝试设置layout_gravity="center"layout_gravity="center_horizontal"因为我认为图书馆的创建者会尝试获取此属性。

答案 2 :(得分:0)

尝试替换此代码:

compile files('libs/gama_wheel_v1.0.jar')
compile files('libs/PayPalAndroidSDK.jar')

使用此代码:

compile fileTree(dir: 'libs', include: '*.jar')

答案 3 :(得分:-1)

Caused by: java.lang.UnsupportedOperationException: Can't convert to integer: type=0x3
        at android.content.res.TypedArray.getInteger(TypedArray.java:368)
        at com.digitalaria.gama.wheel.WheelBehavior.<init>(WheelBehavior.java:117)
        at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:83)
        at com.digitalaria.gama.wheel.Wheel.<init>(Wheel.java:68)

我认为你需要研究这个。不确定Wheel是否是您制作或下载的内容,但它的设置似乎有问题。