Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:23:34+00:00 2026-06-12T08:23:34+00:00

So, Im some kind a noob in java and I’m trying to make a

  • 0

So, Im some kind a noob in java and I’m trying to make a app for android.
Î’m getting some errors but I cant solve them. Can anyone help me finding whatthe problem is ?

Here is my 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;
    }


}

My Reta class:

    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);

    }
}

My DrawView class:

    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);
        }
    }
}

And my Ponto2D class:

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;
    }

}

Now i have(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.

Also in DrawView.java, line 34 I get:

- 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.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:23:36+00:00Added an answer on June 12, 2026 at 8:23 am

    Look at this

    public class MainActivity extends Activity {
    
    Ponto2D patual = new Ponto2D(); <---- here
    //...
    }
    

    you never defined a Ponto2D() constructor in your class.

    Add a

    public Ponto2D()
    {
       x = -1;
       y = -1;
    }
    
    public Ponto2D(int x, int y)
    {
       this();
       this.x = x;
       this.y = y;
    }
    

    Part 2:

       public float X=0;
       public float Y=0;
    

    and later you do this

       Ponto2D patual = new Ponto2D(event.getX(), event.getY());
    

    which should really be

       Ponto2D patual = new Ponto2D((int)event.getX(), (int)event.getY());
    

    or you rework your Ponto2D class to look like this

    public class Ponto2D 
    {
    
    float x;
    float y;
    
    public Ponto2D ()
    {
        x=-1.0;
        y=-1.0;
    }
    
    public Ponto2D(float x, float y)
    {
        this();
        this.x = x;
        this.y = y;
    }
    } //end of class
    

    Part 3:

    ok, i’ll describe each error now.

    • The constructor Ponto2D(float, float) is undefined – we covered this one.
    • fim cannot be resolved to a variable – you never defined ‘fim’ in your MainActivity class. you need to use defined values. I’m guessing you wanted to use the ‘fim’ from your Reta class? in that case…

      Reta r1 = new Reta (inicio, fim);

    change this to

    Reta r1 = new Reta (new Ponto2D(), new Ponto2D());
    

    or

    Reta r1 = new Reta (new Ponto2D(<your values>), new Ponto2D(<values again>));
    
    • inicio cannot be resolved to a variable
      same thing as previous one.

    • line 47: Syntax error on token “[“, Expression expected after this token

              DrawView.ar[contador] =rl[];
      
              inicio.X = \.X;
              inicio.Y = fim.Y;
      

    this will never compile son. I don’t know what you’re trying but I suggest you gather your thoughts on this one 😀

    • Cannot refer to a non-final variable rl inside an inner class defined in a different method

    this one is interesting. this means that you cannot target rl, which is defined in a outer class from an inner class. So to fix it, just swap this

    RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl);
    

    with this

    final RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl);
    

    this error can sometimes be tricky to fix, sometimes you just add final, sometimes you need a final copy of your variable and some other times you need to really restructure your code. fortunately, this time adding final will do.

    • The field DrawView.ar is not visible

    open your DrawView class and see this

    public class DrawView extends View {
    public Paint paint = new Paint();
    
    Reta ar[] = new Reta [10];  //offending line
    public int a;
    //...
    

    so either make that field public like

    public class DrawView extends View
    {
        public Paint paint = new Paint();
    
        public Reta ar[] = new Reta [10];
        //... 
    }
    

    or generate getters/setters.

    • The type of the expression must be an array type but it resolved to RelativeLayout
      once you gather your thoughts on the beforementioned one, this one will automagically disappear. trust me, i’m an engineer 😉

    • The field Reta.inicio is not visible,
      this is self-explanatory by now…

      public class Reta
      {
      public Ponto2D inicio;
      public Ponto2D fim;
      public int cor;
      //…
      }

    • The field Reta.inicio is not visible

    • The field Ponto2D.x is not visible.

    see, this is why you use getters and setters and don’t access the class’s fields directly from different classes.

    Try to make it like this

    public class Ponto2D 
    {
        private int x; //2d plane shouldn't use floating coordinates.
        private int y;
    
        Ponto2D() { }; //ctor does nothing.
    
        public Ponto2D(int x, int y)
        {
           this();
           this.x = x;
           this.y = y;
        }
    
        public int getX() { return x; }
        public int getY() { return y; }
    }
    
    public class Reta 
    {
        private Ponto2D inicio;
        private Ponto2D fim;
        private int cor;
    
        Reta()
        {
           fin = new Ponta2D(); //might cause an error because it's not public
           inicio = new Ponta2D(-1, -1); //this should be ok 
        }
    
        public Reta(Ponto2D p1, Ponto2D p2)
        {
    

    // this.inicio = new Ponto2D(p1.getX(), p1.getY()); //this is bullshit really
    // this.fim = new Ponto2D(p2.getX(), p2.getY());
    this.inicio = p1;
    this.fim = p2; //lets use these instead of new objects. unless you want new objects.
    }
    }

    this code-style will give you an idea how to avoid mistakes like these.

    last part:

    I’ll help you with this one, the rest you will have to figure out on your own if you ever want to make a living out of this… the errors you have are student-level beginner programming ones, not really tied to Java or Android. Those you need to understand and know how to resolve yourself because noone will waste time fixing undefined references for you, and it is even rude to bring it up like that (it shows you didn’t even read your code)

    Cannot make a static reference to the non-static field DrawView.ar

    Ok, so here’s waht you did:

    public class DrawView extends View {
    public Paint paint = new Paint();
    
    Reta ar[] = new Reta [10];
    public int a;
    

    so DrawView class has a member named ar[].

    Normally, you would access it like this:

    DrawView dv = new DrawView();
    System.out.println(Arrays.toString(dv.ar)); // dv.ar, not DrawView.ar
    

    when you invoke it as DrawView.ar that means it is the same for all instances of this class
    which is why it says “cannot refer to non-static variable ar in a static manner”.

    When things are ‘static’ they are shared/same/common throughout all instances of that class.

    So if you do this

    public class DrawView extends View {
    public Paint paint = new Paint();

    static Reta ar[] = new Reta [10];
    public int a;
    

    all your DrawView instances will have the same Reta array 🙂 Since you progbably want more than one drawview with it’s own rectangles, it should be private. And when it’s private, you cannot target it in a static manner (Class.someMember) but from an instance (classInstance.someMember) or ((new Class).someMember)

    which means…. you decide whether or not Reta ar[] should be private or public.

     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[]; //offending line
                //it should be
                //drawView.ar = something; but thats also wrong because you cannot refer to a non-final variable drawView in a inner-class blahblah so here's what you do
                ((DrawView)v).ar[contador] = rl; //or whatever you want it to be
    

    😉

    If you have further questions, hit the books. Try google. Google your errors 🙂 all of those are really, really common and have been covered thousands of times.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think it's kind of noob question but I'm new to SQL Server in
Some kind of problem I can't resolve… In some app, a method called on
Not sure how noob or advanced this question is, but I've been having kind
I'm kind of a noob in the android world, and doing a pet project
Sorry...I'm kind of a programming noob. I was looking at some problem sets online
I wrote my own server in Java and I'm kind of a noob. The
Ok this is kind of embarassing but I just have a rather noob question.
How can I use IE control or some kind of webbrowser in c++ but
I'm a noob in android, and I need some hints to understand how to
Kind of a noob question, but is there a good way to search for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.