导致班级<unknown>
错误的原因是什么?有两个.xml
个文件。第一个.xml
起作用,第二个杀死应用程序。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.widget.lavkaviews.text.Text
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3 товара на сумму"
android:id="@+id/description"
android:textColor="@color/black" />
<com.widget.lavkaviews.text.Text
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/summ"
android:layout_alignParentRight="true"
android:textColor="@color/black"
android:layout_toLeftOf="@+id/ruble"
android:layout_alignBottom="@+id/description" />
<com.widget.lavkaviews.PriceText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/finish"
android:text="ОФОРМИТЬ"
android:layout_below="@+id/description"
android:gravity="center"
android:textColor="@color/main"
android:background="@color/lavka_main_red" />
</RelativeLayout>
Вторая
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<!--android:background="@color/main"-->
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/image" />
<com.widget.lavkaviews.text.Text
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/title"
android:textColor="@color/black"
android:maxLines="2"
android:layout_toRightOf="@+id/image" />
<com.widget.lavkaviews.PriceText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/price"/>
<!--<com.widget.lavkaviews.PriceText-->
<!--android:layout_width="80dp"-->
<!--android:layout_height="20dp"-->
<!--android:id="@+id/price"-->
<!--android:textColor="#262626"-->
<!--android:layout_alignParentRight="true" />-->
<com.widget.lavkaviews.Dropdown
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/portion"
android:layout_toLeftOf="@+id/incrementor" />
<!--android:layout_below="@+id/price"-->
<com.widget.lavkaviews.Incrementor
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/incrementor"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/portion" />
<com.widget.core.view.ProductNDIndicator
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/nd"/>
</RelativeLayout>
错误是在PriceText
类膨胀。在第二个.xml
文件中的模拟器(genymotion)和物理设备上产生错误。这是stacktrace
FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #23: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.lavkalavka.pages.cart.CartFragment$CartAdapter.onCreateViewHolder(CartFragment.java:241)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5223)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4449)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4359)
at com.widget.core.layoutmanagers.LinearLayoutManager.measureChild(LinearLayoutManager.java:235)
at com.widget.core.layoutmanagers.LinearLayoutManager.onMeasure(LinearLayoutManager.java:125)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2563)
at android.view.View.measure(View.java:15172)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15172)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1196)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.widget.ScrollView.onMeasure(ScrollView.java:318)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15172)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1196)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.widget.ScrollView.onMeasure(ScrollView.java:318)
at android.view.View.measure(View.java:15172)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15172)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:940)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15172)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
at android.view.View.
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.market.lavkalavka"
>
<uses-sdk android:maxSdkVersion="23" />
<permission android:name="com.market.lavkalavka.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- GCM permissions -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.market.lavkalavka.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- YandexMaps-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:name="com.lavkalavka.App"
android:allowBackup="false"
android:screenOrientation="portrait"
android:configChanges="orientation|screenSize"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:icon="@drawable/logobadge"
android:label="@string/app_name" >
<!-- Yandex метрика-->
<service
android:name="com.yandex.metrica.MetricaService"
android:enabled="true"
android:exported="true"
android:process=":Metrica">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="com.yandex.metrica.IMetricaService"/>
<data android:scheme="metrica"/>
</intent-filter>
<meta-data android:name="metrica:api:level" android:value="32"/>
</service>
<receiver
android:name="com.yandex.metrica.MetricaEventHandler"
android:enabled="true"
android:exported="true">
<!-- INSTALL_REFERRER необходим для трэкинга кампаний -->
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
<receiver android:name="com.lavkalavka.yametrika.InstallReceiver">
<intent-filter android:priority="999">
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
<!-- Yandex метрика-->
<!-- Facebook API-->
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
<!-- Facebook API-->
<!-- VKontakte API-->
<meta-data android:name="com.vk.sdk.AppId" android:value="4695634" />
<!--<activity android:name="com.vk.sdk.VKOpenAuthActivity" />-->
<activity android:name="com.vk.sdk.VKServiceActivity"
android:label="ServiceActivity" android:theme="@style/VK.Transparent" />
<!-- VKontakte API-->
<!-- GCM Service-->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.market.lavkalavka" />
</intent-filter>
</receiver>
<receiver android:name="com.lavkalavka.gcm.UpdateReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" />
<data android:path="com.market.lavkalavka"
android:scheme="package" />
</intent-filter>
</receiver>
<service
android:name="com.lavkalavka.gcm.GCMIntentService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- GCM Service-->
<activity android:name="com.lavkalavka.pages.map.YandexMapActivity"
android:screenOrientation="portrait"/>
<activity android:name="com.lavkalavka.pages.root.DrawerActivity"
android:screenOrientation="portrait"/>
<activity android:name="com.lavkalavka.pages.root.OopsActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:screenOrientation="portrait"/>
<activity android:name="com.lavkalavka.pages.root.ShieldActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
PriceText xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.widget.lavkaviews.text.Text
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#2b2b2b"
android:id="@+id/price"
android:text="133"
android:layout_centerVertical="true" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="@+id/ruble"
android:layout_toRightOf="@+id/price"
android:layout_centerVertical="true" />
</RelativeLayout>
答案 0 :(得分:1)
你的Logcat会抛出什么
FATAL EXCEPTION:main android.view.InflateException:二进制XML文件 第23行:在课堂上输入错误 android.view.LayoutInflater.createView(LayoutInflater.java:613)
com.market.lavkalavka.PriceText
(在XML中)答案 1 :(得分:0)
您的自定义类似乎未从View
扩展。
public class PieChart extends View {
public PieChart(Context context, AttributeSet attrs) {
super(context, attrs);
}
//Do anything specific to your view.
}
查看有关自定义视图的Android Developers文章