unexpected type...whats wrong?

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1289 Views - Last Post: 18 December 2010 - 09:56 PM Rate Topic: -----

#1 zosozeppa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-December 10

unexpected type...whats wrong?

Posted 18 December 2010 - 12:23 PM

ok, i'm new in this and i'm sorry for my gramatic errors but english its not my language...ok...i have a problem with this line

if ((noSale(i+1,j,m))&&((m.obtenerCas(i+1,j).getLibre())=true))

unexpected type
requiered variable found value

now, I know the error is here:

((m.obtenerCas(i+1,j).getLibre())=true)

but dont know why

this are the variables and methods

m = new Laberinto()

this is the class Laberinto
public class Laberinto
{

    private Casillero [][] m;
    
    public Laberinto()
    {
        m = new Casillero [6][6];
    }
    public Casillero obtenerCas(int i, int j)
    {
        return m[i][j];
    }
}



and this is the class Casillero

public class Casillero
{
    private boolean Libre;
    
    public Casillero(boolean p,boolean l,boolean c,boolean C)
    {
        Libre = l;
    }
    public boolean getLibre()
    {
        return Libre;
    }
}



so...i dont know what's wrong and I expect you could help me...

This post has been edited by macosxnerd101: 18 December 2010 - 02:49 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: unexpected type...whats wrong?

#2 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 343
  • View blog
  • Posts: 1,189
  • Joined: 02-April 09

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 12:57 PM

= is for assignment, == is for comparison.
In your if() statement, you are trying to assign a value to the result of a function. Change the = to == and it'll probably be fine.
Was This Post Helpful? 0
  • +
  • -

#3 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 01:40 PM

Does noSale(i+1,j,m) return type boolean? If it doesn't, that's a problem.
Was This Post Helpful? 0
  • +
  • -

#4 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 497
  • View blog
  • Posts: 1,457
  • Joined: 19-October 09

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 01:52 PM

You create a Casillero array to hold space for Casillero objects but you don't insert anything in them. So then calling this method obtenerCas to return a Casillero, your likely to run into a NullPointerException.

Please post your code in these code tags below in the future :).

Posted Image
Was This Post Helpful? 0
  • +
  • -

#5 zosozeppa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-December 10

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 03:24 PM

fixed! thanks...and yes i will...
Was This Post Helpful? 0
  • +
  • -

#6 zosozeppa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-December 10

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 05:57 PM

ok i just fixed that...but now it's not compilling

theese are my classes
public class Casillero
{
    private boolean Pared;
    private boolean Libre;
    private boolean Camino;
    private boolean Caminado;
    
    public Casillero(boolean p,boolean l,boolean c,boolean C)
    {
        Pared = p;
        Libre = l;
        Camino = c;
        Caminado = C;
    }

    public boolean getPared()
    {
        return Pared;
    }
    public boolean getLibre()
    {
        return Libre;
    }
    public boolean getCamino()
    {
        return Camino;
    }
    public boolean getCaminado()
    {
        return Caminado;
    }
    public boolean getInaccesible()
    {
        boolean aux = false;
        
        if ((Caminado==true)||(Pared==true))
            aux = true;
        
        return aux;
    }
   
    public void setPared(boolean a)
    {
        Pared=a;
    }
    public void setLibre(boolean a)
    {
        Libre=a;
    }
    public void setCamino(boolean a)
    {
        Camino=a;
    }
    public void setCaminado(boolean a)
    {
        Caminado=a;
    }
    
    public void esCamino()
    {
        Camino=true;
        Caminado=false;
        Libre=false;
    }
    public void esCaminado()
    {
        Camino=false;
        Caminado=true;
        Libre=false;
    }
}



------------------------------------------------------------------
public class Laberinto
{

    private Casillero [][] m;
    
    public Laberinto()
    {
        m = new Casillero [6][6];
        llenaLab();
    }

    public Casillero obtenerCas(int i, int j)
    {
        return m[i][j];
    }
    public int obtenerLargo()
    {
        return m.length;
    }
    
    public void llenaLab()
    {
        Casillero c1 = new Casillero (false,true,false,false);
        Casillero c2 = new Casillero (false,true,false,false);
        Casillero c3 = new Casillero (true,false,false,false);
        Casillero c4 = new Casillero (false,true,false,false);
        Casillero c5 = new Casillero (false,true,false,false);
        Casillero c6 = new Casillero (false,true,false,false);
        Casillero c7 = new Casillero (true,false,false,false);
        // it just go on like this
        
        m[0][0]= c1;
        m[1][0]= c2;
        m[2][0]= c3;
        m[3][0]= c4;
        m[4][0]= c5;
       
        // and this too
    }
}



------------------------------------------------------
public class Posicion {
    
    private int fila;
    private int columna;
    
    public Posicion() {
        fila = 0;
        columna = 0;
    }
    
    public int getFila() {
        return fila;
    }
    
    public int getColumna() {
        return columna;
    }
    
    public void nuevaPos(int i, int j, Laberinto m)
    {
        if ((noSale(i+1,j,m))&&((m.obtenerCas(i+1,j).getLibre()==true)))
            {
                fila=i+1;
                columna=j;
            }
        else if ((noSale(i,j-1,m))&&((m.obtenerCas(i,j-1).getLibre())==true))
                {
                    fila=i;
                    columna=j-1;
                }
            else if ((noSale(i-1,j,m))&&((m.obtenerCas(i-1,j).getLibre())==true))
            {
                fila=i-1;
                columna=j;
            }
        
                else 
                    {
                        fila=i;
                        columna=j+1;
                    }
    }
    
    public void anteriorPos(int i, int j, Laberinto m)
    {
        if ((noSale(i+1,j,m))&&((m.obtenerCas(i+1,j).getCamino())==true))
            {
                fila=i;
                columna=j+1;
            }
        else if ((noSale(i-1,j,m))&&((m.obtenerCas(i-1,j).getCamino())==true))
                {
                    fila=i-1;
                    columna=j;
                }
            else if ((noSale(i,j-1,m))&&((m.obtenerCas(i,j-1).getCamino())==true))
            {
                fila=i;
                columna=j-1;
            }
        
                else 
                    {
                        fila=i+1;
                        columna=j;
                    }
    }
        
    public boolean noSale(int i, int j, Laberinto m)
    {
          if ((i>=0)&&(j>=0)&&(i<m.obtenerLargo())&&(j<m.obtenerLargo()))
            return true;
          else return false;
    }
    
}


----------------------------------------------------------------


public class Recorrido
{
    public Laberinto lab;
    int cap;
    Posicion pos;
    public Recorrido (){
        lab = new Laberinto ();
        pos=new Posicion();
    }
    
    public boolean noSale(int i, int j)
    {
          if ((i>=0)&&(j>=0)&&(i<lab.obtenerLargo())&&(j<lab.obtenerLargo()))
            return true;
          else return false;
    }

    public boolean accesible (int i,int j,int k, int l)
    {
        boolean aux = false;
        if (((k==i-1)&&(j==l))||((k==i+1)&&(j==l))||((k==i)&&(j==l-1))||((k==i)&&(j==l-1)))
            aux = true;
        return aux;    
        
    }
    
    
    
    public boolean hayVacio (int i, int j)
    {
        boolean aux = false;
        
        for (int k=i-1;k<=i+1;k++)
            for (int l=j-i;l<=j+1;j++)
                if (((noSale(k,l))&&(accecible(i,j,k,l))&&((lab.obtenerCas(k,l).getLibre())==true)))
                    aux=true;
                    
        
        return aux;
    }
    
    
    
    public boolean sinSalida (int i, int j)
    {
        boolean aux = false;
        
        for (int k=i-1;k<=i+1;k++)
            for (int l=j-i;l<=j+1;j++)
                if (((noSale(k,l))&&(accecible(i,j,k,l))&&((lab.obtenerCas(k,l).getInaccesible())==true)))
                    aux=true;
        
        return aux;
    }

    public boolean HayCamino(int i, int j)
    {
            if (((i!=lab.obtenerLargo()-1)&&(j!=lab.obtenerLargo()-1))||(sinSalida(i,j)!=true))
                {
                    if (hayVacio(i,j))
                    {
                        lab.obtenerCas(i,j).esCamino();
                        pos.nuevaPos(i,j,lab);
                        HayCamino (pos.getFila(),pos.getColumna());
                    }
                    else
                    {
                        lab.obtenerCas(i,j).esCaminado();
                        pos.anteriorPos(i,j,lab);
                        HayCamino(pos.getFila(),pos.getColumna());
                    }
                }  
            
                if ((i==lab.obtenerLargo()-1)&&(j==lab.obtenerLargo()-1))
                    return true;
                    else return false;
    }
     
}







ok every class it's great but the last one..."Recorrido" it just says "Compilling..." i dont know why...
Was This Post Helpful? 0
  • +
  • -

#7 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 497
  • View blog
  • Posts: 1,457
  • Joined: 19-October 09

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 06:04 PM

I can see a typo on line 36 and 50, instead of accecible, it should be accesible.
Was This Post Helpful? 0
  • +
  • -

#8 zosozeppa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-December 10

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 06:44 PM

yes...i fixed that but still...
Was This Post Helpful? 0
  • +
  • -

#9 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 07:20 PM

Hmm, I threw all your class onto Eclipse and I'm not getting any errors of any kind. Could you post your main method? Besides possibly in that, nothing seems to be wrong, at least syntactically.
Was This Post Helpful? 0
  • +
  • -

#10 zosozeppa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-December 10

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 08:18 PM

well...this is the main method...
public boolean HayCamino(int i, int j)
    {
            if (((i!=lab.obtenerLargo()-1)&&(j!=lab.obtenerLargo()-1))||(sinSalida(i,j)!=true))
                {
                    if (hayVacio(i,j))
                    {
                        lab.obtenerCas(i,j).esCamino();
                        pos.nuevaPos(i,j,lab);
                        HayCamino (pos.getFila(),pos.getColumna());
                    }
                    else
                    {
                        lab.obtenerCas(i,j).esCaminado();
                        pos.anteriorPos(i,j,lab);
                        HayCamino(pos.getFila(),pos.getColumna());
                    }
                }  
            
                if ((i==lab.obtenerLargo()-1)&&(j==lab.obtenerLargo()-1))
                    return true;
                    else return false;
    }


there must be something wrong...but i dont know what
Was This Post Helpful? 0
  • +
  • -

#11 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 09:06 PM

That can't be your whole main method.

You need to actually have a method called main.

Like:
public static void main(String[] args)
{
...
}



I get no errors or anything elsewhere in your code.
Was This Post Helpful? 0
  • +
  • -

#12 zosozeppa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-December 10

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 09:14 PM

oh oh now i get it...here it is..
import IPOO.ES;

public class tester {
    public static void main(String[] args) {
        Laberinto lab = new Laberinto ();
        Recorrido rec = new Recorrido ();
        ES.mostrar(" "+ rec.HayCamino(0,0));
        
        for (int k=0;k<lab.obtenerLargo();k++)
            {
                System.out.println();
                for (int l=0;l<lab.obtenerLargo();l++)
                    {
                        ES.mostrar(lab.obtenerCas(k,l).obtenerEstado());
                   
                    }
                }
}
}


(ES.mostrar it's like a "System.out.print")

and here is the rest of the class Laberinto

public class Laberinto
{

    private Casillero [][] m;
    
    public Laberinto()
    {
        m = new Casillero [6][6];
        llenaLab();
    }

    public Casillero obtenerCas(int i, int j)
    {
        return m[i][j];
    }
    public int obtenerLargo()
    {
        return m.length;
    }
    
    public void llenaLab()
    {
        Casillero c1 = new Casillero (false,true,false,false);
        Casillero c2 = new Casillero (false,true,false,false);
        Casillero c3 = new Casillero (true,false,false,false);
        Casillero c4 = new Casillero (false,true,false,false);
        Casillero c5 = new Casillero (false,true,false,false);
        Casillero c6 = new Casillero (false,true,false,false);
        Casillero c7 = new Casillero (true,false,false,false);
        Casillero c8 = new Casillero (false,true,false,false);
        Casillero c9 = new Casillero (false,true,false,false);
        Casillero c10 = new Casillero (false,true,false,false);
        Casillero c11 = new Casillero (true,false,false,false);
        Casillero c12 = new Casillero (false,true,false,false);
        Casillero c13 = new Casillero (true,false,false,false);
        Casillero c14 = new Casillero (true,false,false,false);
        Casillero c15 = new Casillero (true,false,false,false);
        Casillero c16 = new Casillero (false,true,false,false);
        Casillero c17 = new Casillero (true,false,false,false);
        Casillero c18 = new Casillero (true,false,false,false);
        Casillero c19 = new Casillero (false,true,false,false);
        Casillero c20 = new Casillero (false,true,false,false);
        Casillero c21= new Casillero (true,false,false,false);
        Casillero c22= new Casillero (false,true,false,false);
        Casillero c23= new Casillero (true,true,false,false);
        Casillero c24= new Casillero (false,true,false,false);
        Casillero c25= new Casillero (false,true,false,false);
        Casillero c26= new Casillero (true,false,false,false);
        Casillero c27= new Casillero (false,true,false,false);
        Casillero c28= new Casillero (false,true,false,false);
        Casillero c29= new Casillero (false,true,false,false);
        Casillero c30= new Casillero (false,true,false,false);
        Casillero c31= new Casillero (false,true,false,false);
        Casillero c32= new Casillero (false,true,false,false);
        Casillero c33= new Casillero (false,true,false,false);
        Casillero c34= new Casillero (true,false,false,false);
        Casillero c35= new Casillero (true,false,false,false);
        Casillero c36= new Casillero (false,true,false,false);
        
        m[0][0]= c1;
        m[1][0]= c2;
        m[2][0]= c3;
        m[3][0]= c4;
        m[4][0]= c5;
        m[5][0]= c6;
        m[0][1]= c7;
        m[1][1]= c8;
        m[2][1]= c9;
        m[3][1]= c10;
        m[4][1]= c11;
        m[5][1]= c12;
        m[0][2]= c13;
        m[1][2]= c14;
        m[2][2]= c15;
        m[3][2]= c16;
        m[4][2]= c17;
        m[5][2]= c18;
        m[0][3]= c19;
        m[1][3]= c20;
        m[2][3]= c21;
        m[3][3]= c22;
        m[4][3]= c23;
        m[5][3]= c24;
        m[0][4]= c25;
        m[1][4]= c26;
        m[2][4]= c27;
        m[3][4]= c28;
        m[4][4]= c29;
        m[5][4]= c30;
        m[0][5]= c31;
        m[1][5]= c32;
        m[2][5]= c33;
        m[3][5]= c34;
        m[4][5]= c35;
        m[5][5]= c36;
    }
}




(What I'm trying to do is resolve a Labyrinth (Laberinto) using backtracking)
Was This Post Helpful? 0
  • +
  • -

#13 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 09:35 PM

Well I haven't looked at the logical side of the code, but from what you said you're just having trouble with getting the Recorrido class to compile so that's our first priority right now.

I loaded your code from above into Eclipse and besides the fact that I don't have whatever IPOO is, nothing is wrong.

There's no reason why you should be having trouble with the "Recorrido" class. Perhaps you are try to compile it wrong? How are you compiling? And what happens exactly when you try to compile it, it just never ends? Or are you getting errors thrown?
Was This Post Helpful? 0
  • +
  • -

#14 zosozeppa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 18-December 10

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 09:41 PM

nono...right now it's compilling good...the problem is that when i try to use the main it doesn't work...i mean...if a just print the Laberinto that works...but when i try to make work the other part (using the Recorrido object "rec") it just doesn't do anything and a have to reset the virtual machine...

i hope you understand me...its like...i can't run it...
Was This Post Helpful? 0
  • +
  • -

#15 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: unexpected type...whats wrong?

Posted 18 December 2010 - 09:45 PM

View Postzosozeppa, on 18 December 2010 - 10:14 PM, said:

oh oh now i get it...here it is..
import IPOO.ES;

public class tester {
    public static void main(String[] args) {
        Laberinto lab = new Laberinto ();
        Recorrido rec = new Recorrido ();
        ES.mostrar(" "+ rec.HayCamino(0,0));
        
        for (int k=0;k<lab.obtenerLargo();k++)
            {
                System.out.println();
                for (int l=0;l<lab.obtenerLargo();l++)
                    {
                        ES.mostrar(lab.obtenerCas(k,l).obtenerEstado());
                   
                    }
                }
}
}


(ES.mostrar it's like a "System.out.print")

and here is the rest of the class Laberinto

public class Laberinto
{

    private Casillero [][] m;
    
    public Laberinto()
    {
        m = new Casillero [6][6];
        llenaLab();
    }

    public Casillero obtenerCas(int i, int j)
    {
        return m[i][j];
    }
    public int obtenerLargo()
    {
        return m.length;
    }
    
    public void llenaLab()
    {
        Casillero c1 = new Casillero (false,true,false,false);
        Casillero c2 = new Casillero (false,true,false,false);
        Casillero c3 = new Casillero (true,false,false,false);
        Casillero c4 = new Casillero (false,true,false,false);
        Casillero c5 = new Casillero (false,true,false,false);
        Casillero c6 = new Casillero (false,true,false,false);
        Casillero c7 = new Casillero (true,false,false,false);
        Casillero c8 = new Casillero (false,true,false,false);
        Casillero c9 = new Casillero (false,true,false,false);
        Casillero c10 = new Casillero (false,true,false,false);
        Casillero c11 = new Casillero (true,false,false,false);
        Casillero c12 = new Casillero (false,true,false,false);
        Casillero c13 = new Casillero (true,false,false,false);
        Casillero c14 = new Casillero (true,false,false,false);
        Casillero c15 = new Casillero (true,false,false,false);
        Casillero c16 = new Casillero (false,true,false,false);
        Casillero c17 = new Casillero (true,false,false,false);
        Casillero c18 = new Casillero (true,false,false,false);
        Casillero c19 = new Casillero (false,true,false,false);
        Casillero c20 = new Casillero (false,true,false,false);
        Casillero c21= new Casillero (true,false,false,false);
        Casillero c22= new Casillero (false,true,false,false);
        Casillero c23= new Casillero (true,true,false,false);
        Casillero c24= new Casillero (false,true,false,false);
        Casillero c25= new Casillero (false,true,false,false);
        Casillero c26= new Casillero (true,false,false,false);
        Casillero c27= new Casillero (false,true,false,false);
        Casillero c28= new Casillero (false,true,false,false);
        Casillero c29= new Casillero (false,true,false,false);
        Casillero c30= new Casillero (false,true,false,false);
        Casillero c31= new Casillero (false,true,false,false);
        Casillero c32= new Casillero (false,true,false,false);
        Casillero c33= new Casillero (false,true,false,false);
        Casillero c34= new Casillero (true,false,false,false);
        Casillero c35= new Casillero (true,false,false,false);
        Casillero c36= new Casillero (false,true,false,false);
        
        m[0][0]= c1;
        m[1][0]= c2;
        m[2][0]= c3;
        m[3][0]= c4;
        m[4][0]= c5;
        m[5][0]= c6;
        m[0][1]= c7;
        m[1][1]= c8;
        m[2][1]= c9;
        m[3][1]= c10;
        m[4][1]= c11;
        m[5][1]= c12;
        m[0][2]= c13;
        m[1][2]= c14;
        m[2][2]= c15;
        m[3][2]= c16;
        m[4][2]= c17;
        m[5][2]= c18;
        m[0][3]= c19;
        m[1][3]= c20;
        m[2][3]= c21;
        m[3][3]= c22;
        m[4][3]= c23;
        m[5][3]= c24;
        m[0][4]= c25;
        m[1][4]= c26;
        m[2][4]= c27;
        m[3][4]= c28;
        m[4][4]= c29;
        m[5][4]= c30;
        m[0][5]= c31;
        m[1][5]= c32;
        m[2][5]= c33;
        m[3][5]= c34;
        m[4][5]= c35;
        m[5][5]= c36;
    }
}




(What I'm trying to do is resolve a Labyrinth (Laberinto) using backtracking)

You should learn about arrays before to try to solve that type of problem by a program :)
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2