android.view.InflateException: Binary XML file line #279: Error inflating
class PACKAGE_NAME.views.customViews.CalendarObject
Я много искал на этом сайте, но ни одна из этих проблем не была похожа на мою. Я думаю, что это потому, что эта ошибка из моего настроенного представления, CalendarObject.
Я запустил свое приложение на нескольких телефонах, и оно работало правильно. Но когда я запускаю его на эмуляторе PIXEL_2_XL_API_19, появляется эта ошибка!
Вот мой журнал:
Caused by: android.view.InflateException: Binary XML file line #279: Error
inflating class PACKAGE_NAME.views.customViews.CalendarObject
at android.view.LayoutInflater.createView(LayoutInflater.java:621)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at PACKAGE_NAME.views.fragments.FragmentMonthlyCalendar.onCreateView(FragmentMonthlyCalendar.java:85)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2229)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3221)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3171)
at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:560)
at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5241)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
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:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Вот строка # 85, которая вызывает ошибку в java doc:
View v = inflater.inflate(R.layout.fragment_monthly_calendar, container,
false);
И строка # 279 в файле XML:
<PACKAGE_NAME.views.customViews.CalendarObject
android:layout_width="35dp"
android:layout_height="35dp"
android:text="31" />
Вот класс CalendarObject:
public class CalendarObject extends AppCompatTextView {
public static final boolean VISIBLE = true;
public static final boolean GONE = false;
private Paint mCirclePaint;
private boolean mCircleVisibility, mGiftVisibility;
private float mCircleX, mCircleY, mCircleRadius;
private Bitmap mImage;
public CalendarObject(Context context) {
super(context);
init(null, 0);
}
public CalendarObject(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(attrs, 0);
}
public CalendarObject(Context context, @Nullable AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs, defStyleAttr);
}
private void init(AttributeSet attrs, int defStyleAttrs) {
mCirclePaint = new Paint();
mCirclePaint.setAntiAlias(true);
mCirclePaint.setColor(ContextCompat.getColor(getContext(),
R.color.alertRed));
mCircleX = getWidth() / 6;
mCircleY = getHeight() / 6;
mCircleRadius = 10f;
Drawable drawable = ContextCompat.getDrawable(getContext(),
R.drawable.ic_birthday);
mImage = drawableToBitmap(drawable);
}
private Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable)
return ((BitmapDrawable)drawable).getBitmap();
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth() /
2, drawable.getIntrinsicHeight() / 2,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
@Override
protected void onDraw(Canvas canvas) {
if (mCircleVisibility) {
if (mCircleX == 0f || mCircleY == 0f || mCircleRadius == 0f) {
mCircleX = getWidth() / 6;
mCircleY = getHeight() / 6;
mCircleRadius = 10f;
}
canvas.drawCircle(mCircleX, mCircleY, mCircleRadius,
mCirclePaint);
}
if (mGiftVisibility) {
canvas.drawBitmap(mImage, (float) 5 * getWidth() / 7, 0,
null);
}
super.onDraw(canvas);
}
public void setCircleVisibility(boolean visibility) {
mCircleVisibility = visibility;
postInvalidate();
}
public boolean getCircleVisibility() {
return mCircleVisibility;
}
public void setGiftVisibility(boolean visibility) {
mGiftVisibility = visibility;
postInvalidate();
}
public boolean getGiftVisibility() {
return mGiftVisibility;
}
}
Может кто-нибудь помочь мне, почему эта ошибка происходит на API_19?