Question

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.

Était-ce utile?

La solution

<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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top