2

My application stop and I ge Binary XML file error on line #0. It`s kinda weird, because I didn't see problem like this with line 0, so I need your help, everyone. Thanks! This Works Fine On API greater than 20 only lower than API devices is crashing the application

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.vickyy.iwasframed, PID: 7818
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vickyy.iwasframed/com.example.vickyy.iwasframed.ImageSize}: android.view.InflateException: Binary XML file line #0: Error inflating class com.example.vickyy.iwasframed.CustomFrame
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
                  at android.app.ActivityThread.access$900(ActivityThread.java:161)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:157)
                  at android.app.ActivityThread.main(ActivityThread.java:5356)
                  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:1265)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
                  at dalvik.system.NativeStart.main(Native Method)
               Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.example.vickyy.iwasframed.CustomFrame
                  at android.view.LayoutInflater.createView(LayoutInflater.java:609)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                  at com.example.vickyy.iwasframed.ImageSize.onCreate(ImageSize.java:31)
                  at android.app.Activity.performCreate(Activity.java:5426)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) 
                  at android.app.ActivityThread.access$900(ActivityThread.java:161) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:157) 
                  at android.app.ActivityThread.main(ActivityThread.java:5356) 
                  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:1265) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
                  at dalvik.system.NativeStart.main(Native Method) 
               Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
                  at java.lang.Class.getConstructorOrMethod(Class.java:472)
                  at java.lang.Class.getConstructor(Class.java:446)
                  at android.view.LayoutInflater.createView(LayoutInflater.java:574)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
                  at com.example.vickyy.iwasframed.ImageSize.onCreate(ImageSize.java:31) 
                  at android.app.Activity.performCreate(Activity.java:5426) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363) 
                  at android.app.ActivityThread.access$900(ActivityThread.java:161) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:157) 
                  at android.app.ActivityThread.main(ActivityThread.java:5356) 
                  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:1265) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) 
                  at dalvik.system.NativeStart.main(Native Method) 

I/Process: Sending signal. PID: 7818 SIG: 9 Application terminated.

this is xmlFile

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/AppColor"
tools:context="com.example.vickyy.iwasframed.FrameActivity">

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:id="@+id/toolbar"
    android:background="@color/ActionBarColor">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/ActionBarColor">


        <Button
            android:id="@+id/btnDone"
            android:layout_width="45dp"
            android:layout_height="30dp"
            android:text="Done"
            android:layout_centerVertical="true"
            android:textColor="@android:color/white"
            android:backgroundTint="@color/ButtonColor"
            android:layout_alignParentLeft="true"
            android:textSize="8sp"/>


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="USE IMAGE SIZE"
            android:textColor="@android:color/white"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:textStyle="bold"
            android:textSize="16sp"/>


    </RelativeLayout>


</android.support.v7.widget.Toolbar>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="3"
        android:orientation="horizontal"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="WIDTH:"
            android:layout_weight="1"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="HEIGHT:"
            android:layout_weight="1"
            android:layout_marginLeft="10dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="MAT OVERLAP:"
            android:layout_weight="1"
            android:layout_marginLeft="10dp"/>




    </LinearLayout>

</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="0dp"
    android:layout_marginRight="10dp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="3"
        android:orientation="horizontal">
    <EditText
        android:layout_weight="1"
        android:id="@+id/edtWidth"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:paddingLeft="10dp"
        android:layout_toLeftOf="@+id/txtX"
        android:textSize="10sp"

        android:textStyle="bold"
        android:textCursorDrawable="@null"
        android:background="@drawable/custom_edittext"
        android:inputType="numberDecimal"
        android:layout_marginRight="10dp">

    </EditText>





    <EditText
        android:layout_weight="1"
        android:id="@+id/edtHeight"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:layout_toRightOf="@+id/txtX"
        android:textCursorDrawable="@null"
        android:layout_marginLeft="10dp"
        android:textSize="10sp"
        android:paddingLeft="10dp"

        android:textStyle="bold"
        android:inputType="numberDecimal"
        android:background="@drawable/custom_edittext"
        android:layout_alignParentRight="true">

    </EditText>

        <EditText
            android:layout_weight="1"
            android:id="@+id/edtOverlap"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_toRightOf="@+id/txtX"
            android:textCursorDrawable="@null"
            android:layout_marginLeft="10dp"
            android:textSize="10sp"
            android:paddingLeft="10dp"

            android:textStyle="bold"
            android:inputType="numberDecimal"
            android:background="@drawable/custom_edittext"
            android:layout_alignParentRight="true"></EditText>

    </LinearLayout>

</RelativeLayout>



<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:id="@+id/frameLayout">

    <com.example.vickyy.iwasframed.CustomFrame
        android:id="@+id/imgFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ImageView
        android:id="@+id/imgView"
        android:layout_width="255dp"
        android:layout_height="360dp"
        android:scaleType="fitXY"
        android:layout_gravity="center"
        android:src="@drawable/flower"
        />

</FrameLayout>

and this is the custom class that i code for draw rectangle with double and triple Mat

public class CustomFrame extends AppCompatImageView{


Paint paint;
int top,left,right,bottom;
Context context;
public CustomFrame(Context context) {
    super(context);
    paint = new Paint();
    this.context=context;
}

CustomFrame(Context context, AttributeSet attrs) {
    super(context, attrs);
}

CustomFrame(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    SharedPreferences sharedPreferences = getContext().getSharedPreferences("Params", Context.MODE_PRIVATE);
    int color = sharedPreferences.getInt("color",R.color.black);
    int canvasW = getWidth();
    int canvasH = getHeight();
    Point centerOfCanvas = new Point(canvasW / 2, canvasH / 2);
    int width = sharedPreferences.getInt("width",0);
    int height = sharedPreferences.getInt("height",0);
    int overLap=sharedPreferences.getInt("OverLap",0);
    boolean start=sharedPreferences.getBoolean("start",false);


    int rectW = width*75;  //convert to pixel
    int rectH = height*75;
    left = centerOfCanvas.x - (rectW / 2);
    top = centerOfCanvas.y - (rectH / 2);
    right = centerOfCanvas.x + (rectW / 2);
    bottom = centerOfCanvas.y + (rectH / 2);
    paint = new Paint();
    paint.setColor(color);
    paint.setStyle(Paint.Style.STROKE);
/*    if(start) {
        paint.setStrokeWidth(20);
    }
    else{

    }*/
    paint.setStrokeWidth(overLap);
    int l,t,r,b;
    int tripleLeft,tripleTop,tripleRight,tripleBottom;



    boolean doubleMat = sharedPreferences.getBoolean("DoubleMat",false);
    boolean tripleMat = sharedPreferences.getBoolean("TripleMat",false);

    if(doubleMat){
        int matHeight = sharedPreferences.getInt("MatHeight",0);
        int matWidth = sharedPreferences.getInt("MatWidth",0);
        int thickness=sharedPreferences.getInt("Doublethickness",0);
        int matW = (width)*75;
        int matH = (height)*75;
        int matw=matW-overLap;
        int math=matH-overLap;
         l = centerOfCanvas.x - (matw / 2);
         t = centerOfCanvas.y - (math / 2);
         r = centerOfCanvas.x + (matw / 2);
         b = centerOfCanvas.y + (math / 2);
        Paint paint1 = new Paint();
        paint1.setColor(color);
        paint1.setStyle(Paint.Style.STROKE);

        paint1.setStrokeWidth(thickness);      //inside

        paint.setStrokeWidth(overLap);  //mat

        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("MatHeight",math);
        editor.putInt("MatWidth",matw);
        editor.commit();

        canvas.drawRect(left, top, right, bottom, paint);
        canvas.drawRect(l, t, r, b, paint1);

    }
    else if(tripleMat){
        int matHeight = sharedPreferences.getInt("MatHeight",0);
        int matWidth = sharedPreferences.getInt("MatWidth",0);
        int dThickness=sharedPreferences.getInt("Doublethickness",0);
        int tThickness=sharedPreferences.getInt("Triplethickness",0);

        int matW = (width)*75;  //-2 here
        int matH = (height)*75;

        int matw=matW-overLap;
        int math=matH-overLap;

        l = centerOfCanvas.x - (matw / 2);
        t = centerOfCanvas.y - (math / 2);
        r = centerOfCanvas.x + (matw / 2);
        b = centerOfCanvas.y + (math / 2);  //inside

        int tripleWidth=(width)*75;
        int tripleHeight=(height)*75;

        int tmatw=tripleWidth-dThickness-overLap;
        int tmath=tripleHeight-dThickness-overLap;

        tripleLeft=centerOfCanvas.x-(tmatw/2);
        tripleTop=centerOfCanvas.y-(tmath/2);
        tripleRight=centerOfCanvas.x+(tmatw/2);
        tripleBottom=centerOfCanvas.y+(tmath/2);

        Paint triplePaint=new Paint();
        triplePaint.setColor(color);
        triplePaint.setStyle(Paint.Style.STROKE);

        triplePaint.setStrokeWidth(overLap);

        Paint paint1 = new Paint();
        paint1.setColor(color);
        paint1.setStyle(Paint.Style.STROKE);


        paint1.setStrokeWidth(dThickness);      //inside
        paint.setStrokeWidth((int)tThickness);  //mat

        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("MatHeight",tmath);
        editor.putInt("MatWidth",tmatw);
        editor.commit();

        canvas.drawRect(left, top, right, bottom, triplePaint); //outer
        canvas.drawRect(l, t, r, b, paint1);  //inside
       canvas.drawRect(tripleLeft,tripleTop,tripleRight,tripleBottom,paint); //outside

    }
    else {

   /*     Rect r=new Rect(left,top,right,bottom);
        //left
        canvas.drawLine(r.left,r.top,r.left,r.bottom,paint);
        //top
        canvas.drawLine(r.left,r.top,r.right,r.top,paint2);
        //right
        canvas.drawLine(r.right,r.top,r.right,r.bottom,paint);
        //bottom
        canvas.drawLine(r.left,r.bottom,r.right,r.bottom,paint2);*/

       // canvas.drawLine();
       // String text=String.valueOf(overLap);
       canvas.drawRect(left, top, right, bottom, paint);
    //   canvas.drawText(text,left,bottom,paint);
     }

   }

 }
5
  • 3
    The constructors in CustomFrame must be explicitly public. Commented Nov 18, 2017 at 6:57
  • Are you sure your package name com.example.vickyy.iwasframed is correct? Commented Nov 18, 2017 at 6:58
  • @Muhammad have you posted the full xml file?? Commented Nov 18, 2017 at 7:00
  • yes i posted full xml file on the last of file i declare custom class tag Commented Nov 18, 2017 at 7:04
  • thnkx its wokred when constructor goes to public thnkx Commented Nov 18, 2017 at 7:06

1 Answer 1

3

Your constructors need to be public. It can't access a private constructor when inflating. Particularly the 2 variable one (your one variable is the only public one right now).

Sign up to request clarification or add additional context in comments.

1 Comment

thnkx its wokred thnku

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.