Please, i got many errors on my code really i need your help.
Errors:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: tools.myapp.app1, PID: 23986
java.lang.RuntimeException: Unable to start activity ComponentInfo{tools.myapp.app1/tools.myapp.app1.activitys.GreatingCardShowActivity}: android.view.InflateException: Binary XML file line #58 in tools.myapp.app1:layout/activity_greating_card_show: Binary XML file line #58 in tools.myapp.app1:layout/activity_greating_card_show: Error inflating class tools.myapp.app1.StickerView.StickerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3479)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3651)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2104)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7861)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Caused by: android.view.InflateException: Binary XML file line #58 in tools.myapp.app1:layout/activity_greating_card_show: Binary XML file line #58 in tools.myapp.app1:layout/activity_greating_card_show: Error inflating class tools.myapp.app1.StickerView.StickerView
Caused by: android.view.InflateException: Binary XML file line #58 in tools.myapp.app1:layout/activity_greating_card_show: Error inflating class tools.myapp.app1.StickerView.StickerView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:856)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1008)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:963)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1125)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1086)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1128)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1086)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1128)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1086)
at android.view.LayoutInflater.inflate(LayoutInflater.java:684)
at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at `androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:706)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at tools.myapp.app1.activitys.GreatingCardShowActivity.onCreate(GreatingCardShowActivity.java:1001)
at android.app.Activity.performCreate(Activity.java:8109)
at android.app.Activity.performCreate(Activity.java:8083)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3452)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3651)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2104)
at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7861)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.drawable.Drawable.getIntrinsicWidth()' on a null object reference
at tools.myapp.app1.StickerView.DrawableSticker.getWidth(DrawableSticker.java:38)
at tools.myapp.app1.StickerView.DrawableSticker.<init>(DrawableSticker.java:10)
at tools.myapp.app1.StickerView.BitmapStickerIcon.<init>(BitmapStickerIcon.java:16)
at tools.myapp.app1.StickerView.StickerView.<init>(StickerView.java:129)
at tools.myapp.app1.StickerView.StickerView.<init>(StickerView.java:111)
Here: layout/activity_greating_card_show
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_ss">
code......
**//this is a line #58 that the compiler marked**
<tools.myapp.app1.StickerView.StickerView
android:id="@ id/stickerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_margin="@dimen/_8sdp"
android:visibility="visible" />
</RelativeLayout>
Here: GreatingCardShowActivity/onCreate
public void onCreate(@Nullable Bundle bundle) {
ImageView imageView;
float f;
super.onCreate(bundle);
**//the compiler select this line #1001**
setContentView(R.layout.activity_greating_card_show);
InterstitialAdHelper instance = InterstitialAdHelper.Companion.getInstance();
if (instance == null) {
Intrinsics.throwNpe();
}
instance.load(this, this);
this.activity = this;
this.assetManager = getAssets();
this.mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
if (Share.ActivityCardCreate) {
this.bgposition = getIntent().getStringExtra("bgposition");
Log.e("val", "onCreate: bg pos-->" this.bgposition);
} else {
Intent intent = getIntent();
this.gretingcatname = intent.getStringExtra("gretingcatname");
this.pos = intent.getIntExtra("pos", 0);
}
initView();
if (Share.ActivityCardCreate || Share.ActivityGalleryCardCreate) {
ImageView imageView2 = this.iv_custom_sticker_view;
if (imageView2 == null) {
Intrinsics.throwNpe();
}
f = 1.0f;
imageView2.setAlpha(1.0f);
ImageView imageView3 = this.iv_gc_quotes;
if (imageView3 == null) {
Intrinsics.throwNpe();
}
imageView3.setAlpha(1.0f);
imageView = this.iv_ad_frame;
} else {
ImageView imageView4 = this.iv_custom_sticker_view;
if (imageView4 == null) {
Intrinsics.throwNpe();
}
f = 0.5f;
imageView4.setAlpha(0.5f);
ImageView imageView5 = this.iv_gc_quotes;
if (imageView5 == null) {
Intrinsics.throwNpe();
}
imageView5.setAlpha(0.5f);
imageView = this.iv_ad_frame;
}
imageView.setAlpha(f);
initAction();
drawables_sticker.clear();
}
Here: class DrawableSticker
public class DrawableSticker extends Sticker {
private Drawable mDrawable;
**// Below is line #10 the compiler select getWidth() in this line**
private final Rect mRealBounds = new Rect(0, 0, getWidth(), getHeight());
public DrawableSticker(Drawable drawable) {
this.mDrawable = drawable;
this.a = new Matrix();
}
@Override
public void draw(Canvas canvas) {
canvas.save();
canvas.concat(this.a);
this.mDrawable.setBounds(this.mRealBounds);
this.mDrawable.draw(canvas);
canvas.restore();
}
@Override
public Drawable getDrawable() {
return this.mDrawable;
}
@Override
public int getHeight() {
return this.mDrawable.getIntrinsicHeight();
}
@Override
public int getWidth() {
return this.mDrawable.getIntrinsicWidth(); **//here line #38**
}
@Override
public void release() {
super.release();
if (this.mDrawable != null) {
this.mDrawable = null;
}
}
@Override
public void setDrawable(Drawable drawable) {
this.mDrawable = drawable;
}
}
This is : class Sticker "extended in class DrawableSticker"
public abstract class Sticker {
protected Matrix a;
protected boolean b;
private String tag = "";
private float[] mMatrixValues = new float[9];
private float getMatrixAngle(@NonNull Matrix matrix) {
return (float) (-(Math.atan2((double) getMatrixValue(matrix, 1), (double)
getMatrixValue(matrix, 0)) * 57.29577951308232d));
}
private float getMatrixScale(@NonNull Matrix matrix) {
return (float) Math.sqrt(Math.pow((double) getMatrixValue(matrix, 0), 2.0d)
Math.pow((double) getMatrixValue(matrix, 3), 2.0d));
}
private float getMatrixValue(@NonNull Matrix matrix, @IntRange(from = 0, to = 9) int i) {
matrix.getValues(this.mMatrixValues);
return this.mMatrixValues[i];
}
public boolean contains(float f, float f2) {
Matrix matrix = new Matrix();
matrix.setRotate(-getCurrentAngle());
float[] fArr = new float[8];
float[] fArr2 = new float[2];
matrix.mapPoints(fArr, getMappedBoundPoints());
matrix.mapPoints(fArr2, new float[]{f, f2});
return StickerUtils.trapToRect(fArr).contains(fArr2[0], fArr2[1]);
}
public abstract void draw(Canvas canvas);
public RectF getBound() {
return new RectF(0.0f, 0.0f, (float) getWidth(), (float) getHeight());
}
public float[] getBoundPoints() {
return !this.b ? new float[]{0.0f, 0.0f, (float) getWidth(), 0.0f, 0.0f, (float)
getHeight(), (float) getWidth(), (float) getHeight()} : new float[]{(float) getWidth(), 0.0f,
0.0f, 0.0f, (float) getWidth(), (float) getHeight(), 0.0f, (float) getHeight()};
}
public PointF getCenterPoint() {
return new PointF((float) (getWidth() / 2), (float) (getHeight() / 2));
}
public float getCurrentAngle() {
return getMatrixAngle(this.a);
}
public float getCurrentHeight() {
return getMatrixScale(this.a) * ((float) getHeight());
}
public float getCurrentScale() {
return getMatrixScale(this.a);
}
public float getCurrentWidth() {
return getMatrixScale(this.a) * ((float) getWidth());
}
public abstract Drawable getDrawable();
public abstract int getHeight();
public RectF getMappedBound() {
RectF rectF = new RectF();
this.a.mapRect(rectF, getBound());
return rectF;
}
public float[] getMappedBoundPoints() {
float[] fArr = new float[8];
this.a.mapPoints(fArr, getBoundPoints());
return fArr;
}
public PointF getMappedCenterPoint() {
PointF centerPoint = getCenterPoint();
float[] mappedPoints = getMappedPoints(new float[]{centerPoint.x, centerPoint.y});
return new PointF(mappedPoints[0], mappedPoints[1]);
}
public float[] getMappedPoints(float[] fArr) {
float[] fArr2 = new float[fArr.length];
this.a.mapPoints(fArr2, fArr);
return fArr2;
}
public Matrix getMatrix() {
return this.a;
}
public abstract int getWidth();
public boolean isFlipped() {
return this.b;
}
public void release() {
}
public abstract void setDrawable(Drawable drawable);
public void setFlipped(boolean z) {
this.b = z;
}
public void setMatrix(Matrix matrix) {
this.a.set(matrix);
}
public void setTag(String str) {
this.tag = str;
}
}
And this is : class BitmapStickerIcon
public class BitmapStickerIcon extends DrawableSticker {
public static final float DEFAULT_ICON_EXTRA_RADIUS = 10.0f;
public static final float DEFAULT_ICON_RADIUS = 30.0f;
private float x;
private float y;
private float mIconRadius ;
private float mIconExtraRadius ;
public BitmapStickerIcon(Drawable drwbl) {
super(drwbl); **//this is line #16 selected by compiler**
this.mIconRadius = 30.0f;
this.mIconExtraRadius = 10.0f;
}
public void draw(Canvas canvas, Paint paint) {
canvas.drawCircle(this.x, this.y, this.mIconRadius, paint);
super.draw(canvas);
}
public float getIconExtraRadius() {
return this.mIconExtraRadius;
}
public float getIconRadius() {
return this.mIconRadius;
}
public float getX() {
return this.x;
}
public float getY() {
return this.y;
}
public void setIconExtraRadius(float f) {
this.mIconExtraRadius = f;
}
public void setIconRadius(float f) {
this.mIconRadius = f;
}
public void setX(float f) {
this.x = f;
}
public void setY(float f) {
this.y = f;
}
}
Here : class StickerView
public class StickerView extends FrameLayout {
public static final float MAX_SCALE_SIZE = 3.2f;
public static final float MIN_SCALE_SIZE = 0.1f;
private static final String TAG = "StickerView";
public static float[] bitmapPoints;
public static boolean mLocked;
public static List<Sticker> mStickers = new ArrayList();
private Paint mBorderPaint;
private ActionMode mCurrentMode;
private BitmapStickerIcon mDeleteIcon;
private Matrix mDownMatrix;
private float mDownX;
private float mDownY;
private BitmapStickerIcon mEditIcon;
private BitmapStickerIcon mFlipIcon;
private Sticker mHandlingSticker;
private PointF mMidPoint;
private Matrix mMoveMatrix;
private float mOldDistance;
private float mOldRotation;
private OnStickerOperationListener mOnStickerOperationListener;
private Matrix mSizeMatrix;
private RectF mStickerRect;
private int mTouchSlop;
private BitmapStickerIcon mZoomIcon;
public static class kcm1 {
static final int[] aaz;
static {
int[] iArr = new int[ActionMode.values().length];
aaz = iArr;
try {
iArr[ActionMode.NONE.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
aaz[ActionMode.DRAG.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
aaz[ActionMode.ZOOM_WITH_TWO_FINGER.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
aaz[ActionMode.ZOOM_WITH_ICON.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
}
}
public enum ActionMode {
NONE,
DRAG,
ZOOM_WITH_TWO_FINGER,
ZOOM_WITH_ICON,
DELETE,
FLIP_HORIZONTAL,
CLICK
}
public interface OnStickerOperationListener {
void onStickerClicked(Sticker sticker);
void onStickerDeleted(Sticker sticker);
void onStickerDragFinished(Sticker sticker);
void onStickerEdit(Sticker sticker);
void onStickerFlipped(Sticker sticker);
void onStickerZoomFinished(Sticker sticker);
}
public StickerView(Context context) {
this(context, null); **//this line #111 selected by compiler**
}
public StickerView(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0);
}
public StickerView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
this.mOldDistance = 0.0f;
this.mOldRotation = 0.0f;
this.mCurrentMode = ActionMode.NONE;
this.mTouchSlop = 3;
Paint paint = new Paint();
this.mBorderPaint = paint;
paint.setAntiAlias(true);
this.mBorderPaint.setColor(-16777216);
this.mBorderPaint.setAlpha(128);
this.mSizeMatrix = new Matrix();
this.mDownMatrix = new Matrix();
this.mMoveMatrix = new Matrix();
this.mStickerRect = new RectF();
**//Below line #129 the compiler select BitmapStickerIcon**
this.mDeleteIcon = new BitmapStickerIcon(ContextCompat.getDrawable(getContext(), R.drawable.ic_close_white_18dp));
this.mZoomIcon = new BitmapStickerIcon(ContextCompat.getDrawable(getContext(), R.drawable.ic_scale_white_18dp));
} ...more
I have no idea how to fix the errors, I have tested many solutions but nothing changed. I will be happy for your help.
CodePudding user response:
In the StickerView
file:
- Remove the
StickerView(Context context)
constructor - Put the initialization code also in the
StickerView(Context context, AttributeSet attributeSet)
constructor (creating a dedicated method is a good approach) and - Change
this(context, attributeSet, 0)
tosuper(context, attributeSet)
public StickerView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
setup();
}
public StickerView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
setup();
}
public void setup() {
this.mOldDistance = 0.0f;
this.mOldRotation = 0.0f;
this.mCurrentMode = ActionMode.NONE;
this.mTouchSlop = 3;
Paint paint = new Paint();
this.mBorderPaint = paint;
paint.setAntiAlias(true);
this.mBorderPaint.setColor(-16777216);
this.mBorderPaint.setAlpha(128);
this.mSizeMatrix = new Matrix();
this.mDownMatrix = new Matrix();
this.mMoveMatrix = new Matrix();
this.mStickerRect = new RectF();
**//Below line #129 the compiler select BitmapStickerIcon**
this.mDeleteIcon = new BitmapStickerIcon(ContextCompat.getDrawable(getContext(), R.drawable.ic_close_white_18dp));
this.mZoomIcon = new BitmapStickerIcon(ContextCompat.getDrawable(getContext(), R.drawable.ic_scale_white_18dp));
}