だから、私はJavaの初心者で、Android用のアプリを作ろうとしています。いくつかのエラーが発生していますが、解決できません。問題が何であるかを見つけるのを手伝ってくれる人はいますか?
これが私のmainActivityです:
package com.example.w;
//import com.example.jkhgvcxz.R;
import views.DrawView;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
Ponto2D patual = new Ponto2D();
int contador = 0;
DrawView drawView;
View view2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(500, 500);
params.leftMargin = 50;
params.topMargin = 50;
drawView = new DrawView(this);
drawView.setBackgroundColor(Color.WHITE);
rl.addView(drawView, params);
drawView.setOnTouchListener(new View.OnTouchListener() {
// @Override
public boolean onTouch(View v, MotionEvent event) {
Ponto2D patual = new Ponto2D((int)event.getX(), (int)event.getY()); Reta r1 = new Reta (inicio, fim);
DrawView.ar[contador] =rl[];
inicio.X = \.X;
inicio.Y = fim.Y;
contador++;
if (event.getAction()== MotionEvent.ACTION_DOWN)
{
drawView.a=7;
drawView.antigox=drawView.X;
drawView.antigoy=drawView.Y;
drawView.X=event.getX();
drawView.Y=event.getY();
//drawView.draw();
drawView.desenhar_quadrado();}
return true;
}
});
}
public void btn(View v)
{
drawView.desenhar_quadrado();
}
public void btn_verde(View v)
{
drawView.paint.setColor(Color.GREEN);
}
public void btn_vermelho(View v)
{
drawView.paint.setColor(Color.RED);
}
public void btn_preto(View v)
{
drawView.paint.setColor(Color.BLACK);
}
public void btn_azul(View v)
{
drawView.paint.setColor(Color.BLUE);
}
public void btn_amarelo(View v)
{
drawView.paint.setColor(Color.YELLOW);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
私のRetaクラス:
package com.example.w;
public class Reta {
Ponto2D inicio;
Ponto2D fim;
int cor;
public Reta(Ponto2D p1, Ponto2D p2){
inicio = new Ponto2D(p1.x, p1.y);
fim = new Ponto2D(p2.x, p2.y);
}
}
私の DrawView クラス:
package views;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import com.example.w.Reta;
public class DrawView extends View {
public Paint paint = new Paint();
Reta ar[] = new Reta [10];
public int a;
public float antigox=0;
public float antigoy=0;
public float X=0;
public float Y=0;
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLACK);
a=0;
}
public void desenhar_quadrado()
{
invalidate();
}
@Override
public void onDraw(Canvas canvas) {
for(int j=0; j<10; j++){
drawLine(ar[j].inicio.x, ar[j].inicio.y);
}
}
}
そして私の Ponto2D クラス:
package com.example.w;
public class Ponto2D {
int x;
int y;
public Ponto2D()
{
x = -1;
y = -1;
}
public Ponto2D(int x, int y)
{
this();
this.x = x;
this.y = y;
}
}
今私は持っています(44-50)
- The constructor Ponto2D(float, float) is undefined
- fim cannot be resolved to a variable
- inicio cannot be resolved to a variable
- line 47: Syntax error on token "[", Expression expected after this token
- Cannot refer to a non-final variable rl inside an inner class defined in a different method
- The field DrawView.ar is not visible
- The type of the expression must be an array type but it resolved to RelativeLayout
- fim cannot be resolved to a variable - inicio cannot be resolved to a variable.
また、DrawView.java の 34 行目で次のようになります。
- The field Reta.inicio is not visible,
- The method drawLine(int, int) is undefined for the type DrawView
- The field Reta.inicio is not visible
- The field Ponto2D.x is not visible.