1

I was wondering, I have the following source code files:

MainActivity.java

package com.example.bmtitest2;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;

public class MainActivity extends Activity {

    private JavaAbstractionLayer abstr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        abstr = (JavaAbstractionLayer) findViewById(R.id.abstraction);
        abstr.invalidate();

    }

    public void write(String message) {
        new AlertDialog.Builder(this).setMessage(message).show();
    }

    @Override
    public void finish(){
        onDestroy();

    }

}

JavaAbstractionLayer.java

package com.example.bmtitest2;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.View;

public class JavaAbstractionLayer extends View {

    static {
        System.loadLibrary("gestureDetector");
    }

    GenericView classToCall;

    private final int PINK = Color.rgb(255, 192, 203);

    public JavaAbstractionLayer(Context context) {
        super(context);
    }

    public void setClassToCall(ViewController classToCall) {
        this.classToCall = classToCall;
    }

    private native String callGestureAnalysis(float previousX, float previousY, float currentX, float currentY);

    @Override
    public boolean onTouchEvent(MotionEvent event){
        String val = callGestureAnalysis(event.getX(), event.getY(), event.getX(), event.getY());
        boolean issue;
        if(val.equals("TAP")) {
            classToCall.drawCircle(event.getX(), event.getY());
            issue = true;
        } else {
            issue = false;
        }
        return issue;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawCircle(classToCall.getCircleX(), classToCall.getCircleY(), classToCall.getCircleRadius(), classToCall.getCirclePaint());
    }
}

GenericView.java

package com.example.bmtitest2;

import android.graphics.Paint;

public interface GenericView {
    public void drawCircle(float x, float y);
    public float getCircleX();
    public float getCircleY();
    public float getCircleRadius();
    public Paint getCirclePaint();
}

ViewController.java

package com.example.bmtitest2;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;

public class ViewController implements GenericView {
    private float circleX;
    private float circleY;
    private Paint circlePaint;
    private float circleRadius;

    private JavaAbstractionLayer aLayer;

    public ViewController(Context context)
    {
        circleX = 0;
        circleY = 0;
        circleRadius = 100;
        circlePaint = new Paint();
        circlePaint.setColor(Color.RED);
        circlePaint.setStyle(Paint.Style.FILL);
        aLayer = new JavaAbstractionLayer(context);
        aLayer.setClassToCall(this);
    }

    @Override
    public float getCircleX() {
        return circleX;
    }

    public void setCircleX(float circleX) {
        this.circleX = circleX;
    }

    @Override
    public float getCircleY() {
        return circleY;
    }

    public void setCircleY(float circleY) {
        this.circleY = circleY;
    }

    public Paint getCirclePaint() {
        return circlePaint;
    }

    public void setCirclePaint(Paint circlePaint) {
        this.circlePaint = circlePaint;
    }

    public float getCircleRadius() {
        return circleRadius;
    }

    public void setCircleRadius(float circleRadius) {
        this.circleRadius = circleRadius;
    }

    public JavaAbstractionLayer getaLayer() {
        return aLayer;
    }

    public void setaLayer(JavaAbstractionLayer aLayer) {
        this.aLayer = aLayer;
    }

    public void setCircleCords(float x, float y) {
        circleX = x;
        circleY = y;
    }

    public void drawCircle(int circleX, int circleY) {
        float circleXF = (float)circleX;
        float circleYF = (float)circleY;
        drawCircle(circleXF, circleYF);
    }   

    public void setCircleRad(float r) {
        circleRadius = r;
    }

    @Override
    public void drawCircle(float circleX, float circleY) {
        setCircleCords(circleX, circleY);
    }
}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

        <com.example.bmtiTest2
        android:id="@+id/abstraction"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

On runtime, I am getting an InflateException: Binary XML file line #7. I can't seem to figure out at all what would be causing my error. Note that I did not include my C and C++ source code in this post, as I don't think it would be the cause of the error.

3
  • You missed the class name after com.example.bmtiTest2 on your layout XML. Commented Mar 13, 2014 at 2:40
  • In your XML, it looks like it is trying to find a View component called com.example.bmtiTest2, but this is a package name. Shouldn't it be something like com.example.bmtiTest2.MyCustomView Commented Mar 13, 2014 at 2:40
  • Just tried adding my view class name to the XML file, still giving the same error. Commented Mar 13, 2014 at 3:04

1 Answer 1

1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

    <com.example.bmtiTest2
    android:id="@+id/abstraction"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>

What is the com.example.bmtiTest2? It is just your package name,but why is it here? If your defined your view(maybe com.example.bmtiTest2.MyView),the xml should be this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

    <com.example.bmtiTest2.MyView
    android:id="@+id/abstraction"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</RelativeLayout>
Sign up to request clarification or add additional context in comments.

2 Comments

I just tried adding my view class name (JavaAbstractionLayer) to the xml file, still getting the same error.
Your JavaAbstractionLayer is not a valid user-defined view that can be used in the xml.You should have at least a constructor of JavaAbstractionLayer(Context context, AttributeSet attrs).When the Android OS try to inflate your view,it will try to find your constructors with an AttributeSet argument.

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.