类膨胀错误<unknown>从ADB设备开始,但在VB上运行时都很好

时间:2016-02-10 11:08:48

标签: java android xml adb virtual-machine

每当我在平板电脑上运行app android应用程序时,连接到ADB(Android中的USB和开发者模式)。平板显示消息“Unfortunalty stopped”。但是,当我在Android-x86虚拟设备(虚拟盒)上运行应用程序时,一切都很好。 哪里出错了? ADT(Logcat)日志说:

02-10 12:52:39.310    3897-3897/com.test E/AndroidRuntime﹕ FATAL EXCEPTION: main
    android.view.InflateException: Binary XML file line #22: Error inflating class <unknown>
            at android.view.LayoutInflater.createView(LayoutInflater.java:613)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.test.PageSplash.onCreateView(PageSplash.java:17)
            at android.app.Fragment.performCreateView(Fragment.java:1695)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
            at android.app.BackStackRecord.run(BackStackRecord.java:694)
            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
            at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
            at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:153)
            at android.app.ActivityThread.main(ActivityThread.java:5299)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            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:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.test.PageSplash.onCreateView(PageSplash.java:17)
            at android.app.Fragment.performCreateView(Fragment.java:1695)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
            at android.app.BackStackRecord.run(BackStackRecord.java:694)
            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
            at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
            at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:153)
            at android.app.ActivityThread.main(ActivityThread.java:5299)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ArrayIndexOutOfBoundsException: length=25; index=959
            at android.content.res.StringBlock.get(StringBlock.java:64)
            at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
            at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:720)
            at android.content.res.TypedArray.getString(TypedArray.java:124)
            at android.widget.TextView.<init>(TextView.java:971)
            at android.widget.Button.<init>(Button.java:107)
            at android.widget.Button.<init>(Button.java:103)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.test.PageSplash.onCreateView(PageSplash.java:17)
            at android.app.Fragment.performCreateView(Fragment.java:1695)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
            at android.app.BackStackRecord.run(BackStackRecord.java:694)
            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
            at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
            at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:153)
            at android.app.ActivityThread.main(ActivityThread.java:5299)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)

PageSplash xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent" android:background="@color/white"
        >

    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" android:gravity="center_horizontal" android:weightSum="1">
        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView17" android:src="@drawable/splash_image"
                android:layout_gravity="center_horizontal"/>
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/welcome_to_test"
                android:id="@+id/textView34" android:textColor="#404041" android:textSize="24sp"
                android:layout_marginTop="40dp" android:layout_gravity="center_horizontal"/>
        <Button
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:text="@string/login"
                android:id="@+id/btn_login" android:textColor="@color/white" android:background="@drawable/splash_button"
                style="@android:style/Widget.DeviceDefault.Button.Borderless.Small" android:layout_marginTop="34dp"
                android:layout_gravity="center_horizontal" android:textAllCaps="true"/>
        <Button
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:text="@string/continue_as_guest"
                android:id="@+id/btn_guest" android:textColor="@color/white" android:background="@drawable/splash_button"
                style="@android:style/Widget.DeviceDefault.Button.Borderless.Small" android:layout_marginTop="20dp"
                android:layout_gravity="center_horizontal" android:textAllCaps="true"/>
        <Button
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:text="@string/create_account"
                android:id="@+id/btn_join" android:textColor="@color/white" android:background="@drawable/splash_button"
                style="@android:style/Widget.DeviceDefault.Button.Borderless.Small" android:layout_marginTop="20dp"
                android:layout_gravity="center_horizontal" android:textAllCaps="true"/>
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" android:gravity="right" android:layout_marginTop="20dp">
            <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/done"
                    android:id="@+id/btn_done" style="@android:style/Widget.DeviceDefault.Button.Borderless.Small"
                    android:textSize="@dimen/button" android:textColor="@color/main_blue"
                    android:textAllCaps="true" android:layout_marginRight="30dp"/>
        </LinearLayout>
    </LinearLayout>
</ScrollView>

PageSplash java

package com.test;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

public class PageSplash extends Fragment{

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View v = inflater.inflate(R.layout.page_splash, null);

        Button btn_login = (Button) v.findViewById(R.id.btn_login);
        if(btn_login != null)
        {
            btn_login.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Fragment login = new PageLogin();
                    FragmentTransaction ft = getFragmentManager().beginTransaction();
                    ft.replace(R.id.main_content, login);
                    ft.addToBackStack(null);
                    ft.commit();
                }
            });
        }

        Button btn_join = (Button) v.findViewById(R.id.btn_join);
        if(btn_join != null)
        {
            btn_join.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Fragment join = new PageJoin();
                    FragmentTransaction ft = getFragmentManager().beginTransaction();
                    ft.replace(R.id.main_content, join);
                    ft.addToBackStack(null);
                    ft.commit();
                }
            });
        }

        Button btn_guest = (Button) v.findViewById(R.id.btn_guest);
        btn_guest.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Fragment index = new PageIndex();
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction ft = fragmentManager.beginTransaction();
                ft.replace(R.id.main_content, index);
                ft.addToBackStack(null);
                ft.commit();
            }
        });

        Button btn_done = (Button) v.findViewById(R.id.btn_done);
        btn_done.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Fragment index = new PageIndex();
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction ft = fragmentManager.beginTransaction();
                ft.replace(R.id.main_content, index);
                ft.addToBackStack(null);
                ft.commit();
            }
        });

        LinearLayout menu_bottom = (LinearLayout) getActivity().findViewById(R.id.menu_bottom);
        menu_bottom.setVisibility(View.GONE);

        return v;
    }

    public void onPause()
    {
        super.onPause();

        LinearLayout menu_bottom = (LinearLayout) getActivity().findViewById(R.id.menu_bottom);
        menu_bottom.setVisibility(View.VISIBLE);
    }
}

非常感谢

1 个答案:

答案 0 :(得分:0)

显然在

中似乎存在一些问题
<Button
                android:layout_width="220dp"
                android:layout_height="wrap_content"
                android:text="@string/login"
                android:id="@+id/btn_login" android:textColor="@color/white" android:background="@drawable/splash_button"
                style="@android:style/Widget.DeviceDefault.Button.Borderless.Small" android:layout_marginTop="34dp"
                android:layout_gravity="center_horizontal" android:textAllCaps="true"/>

尝试调试@android:style / Widget.DeviceDefault.Button.Borderless.Small