java - 充气类时出错?

标签 java android eclipse

我将一个项目从 Eclipse 迁移到了 Android Studio。在我的项目中,我添加了 this library . 我已将该库作为依赖项添加到我的 gradle 文件中。我可以从我的类(class)导入图书馆。
但它显示了这一点

android.view.InflateException:二进制 XML 文件第 8 行:错误膨胀类 com.digitalaria.gama.wheel.Wheel

在运行应用程序时。

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

渐变

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 */ }
}

最佳答案

相关异常:

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

进行全局搜索

关于java - 充气类时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26729809/

相关文章:

java - 从字符串数组中删除空值的最佳方法

android - 使用android中的另一个 Activity 从捕获中获取图像并在另一个布局中显示图像

java - Eclipse/Spring/Tomcat 6 的奇怪字符编码问题

javascript - 操作系统暂停时恢复 Android webview/在后台应用程序上运行 JavaScript?

python - 在 mac 中将 MySQL Workbench 与 Eclipse 中的 Django 连接

java - "someVariable cannot be resolved"错误在 Eclipse 中针对包含的 JSP 指示

java - 单击事件在使用 Selenium 和 Java 的 MAC OS Safari 13.05 中不起作用

java - 独立 Apache Qpid (amqp) Junit 测试示例

java - 将上传的文件作为电子邮件附加

java - 使用 JEE 部署 Web 应用程序,我可以将其服务用于 Android 应用程序吗?