andandandand
andandandand

Reputation: 22270

Phantom method?

I was getting the following error message while trying to debug my code:

Not able to submit breakpoint MethodBreakpoint [tarea11.Main].contarCapas '(Ljava/util/TreeSet<tarea11/punto>;)I', reason: Method 'contarCapas' with signature '(Ljava/util/TreeSet<tarea11/punto>;)I' does not exist in class tarea11.Main.

Now I realize that the contarCapas method ain't working at all, it's as if it isn't even declared.

Version 1:

package tarea11;


import java.io.File;
import java.io.IOException;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeSet;

/**
 *
 * @author darwin
 */

class punto{
    int x;
    int y;
    boolean usado;


    public punto(int x, int y) {
        this.x = x;
        this.y = y;
        this.usado=false;

    }


    static double pendiente (punto p1, punto p2){
        double M = (p2.y - p1.y) / (p2.x - p1.x);
        return M;

    }

    @Override
    public boolean equals (Object o1){

        if (o1 instanceof punto){

            punto p1 = (punto)o1;
            if (p1.x==this.x&& p1.y==this.y){

                return true;
            }
              return false;

        }

        else

            return false;

    }

    @Override
    public int hashCode() {

       String string = this.x+" "+this.y;
       return string.hashCode();

    }

}

class PointComparator implements Comparator {

    public int compare(Object o1, Object o2){

        punto p1 = (punto)o1;
        punto p2 = (punto)o2;

        if (p1.y>p2.y){
            return 1;
        }
        if(p2.y > p1.y)
        {
            return -1;
        }

        else{

            if(p1.x>p2.x){
                return 1;
            }
            return -1;
        }


    }

}

public class Main {


    static int contarCapas (TreeSet<punto> puntosOrdenados){

        int numeroDeCapas=0;

        HashSet <punto> puntosUsados = new HashSet<punto>();

        while (!puntosOrdenados.isEmpty()){

            punto p= puntosOrdenados.pollFirst();

            puntosUsados.add(p);

            //chequear contra todos los demas para hallar minArco
            double minArco=99999999;
            punto minPunto = new punto(-2001,-2001);
            double arco=0;
            for (punto siguiente: puntosOrdenados){

                if(siguiente.equals(p)){
                    continue;
                }

                arco=Math.atan2(p.y - siguiente.y, p.x - siguiente.x);
                if (arco< minArco){
                    minArco=arco;
                    minPunto = siguiente;
                }

            }

            if (puntosUsados.contains(minPunto)){

                numeroDeCapas= numeroDeCapas+1;

            }

        }

        return numeroDeCapas;

    }


    public static void main(String[] args) {

        PointComparator pointComparator = new PointComparator();

        System.out.println(Math.atan2(-1.0, 1.0));
        //System.out.println(Math.acos(cont))
        Scanner s = new Scanner(System.in);

        try{
        s = new Scanner(new File("entrada.txt"));
        } catch(IOException e){}
        int N,x,y;

        N = s.nextInt();

        while(N!=0){

            punto cebolla[] = new punto[N];

            TreeSet <punto> puntosOrdenados = new TreeSet <punto>(pointComparator);

            for(int i=0;i<N;i++){
                x=s.nextInt(); y=s.nextInt();
                cebolla[i]=new punto(x,y); //borrar?
                puntosOrdenados.add(new punto(x,y));
            }


           int cont= contarCapas(puntosOrdenados);
           System.out.println(cont);

             if(cont%2==0){
                System.out.println("NO");
             }else{
                System.out.println("SI");
             }
             N = s.nextInt();
        }
    }


    }

version 2:

package tarea11;


import java.io.File;
import java.io.IOException;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeSet;

/**
 *
 * @author darwin
 */

class punto{
    int x;
    int y;
    boolean usado;




    public punto(int x, int y) {
        this.x = x;
        this.y = y;
        this.usado=false;

    }


    static double pendiente (punto p1, punto p2){
        double M = (p2.y - p1.y) / (p2.x - p1.x);
        return M;

    }

    @Override
    public boolean equals (Object o1){

        if (o1 instanceof punto){

            punto p1 = (punto)o1;
            if (p1.x==this.x&& p1.y==this.y){

                return true;
            }
              return false;

        }

        else

            return false;

    }

    @Override
    public int hashCode() {

       String string = this.x+" "+this.y;
       return string.hashCode();

    }

}

class PointComparator implements Comparator {

    public int compare(Object o1, Object o2){

        punto p1 = (punto)o1;
        punto p2 = (punto)o2;

        if (p1.y>p2.y){
            return 1;
        }
        if(p2.y > p1.y)
        {
            return -1;
        }

        else{

            if(p1.x>p2.x){
                return 1;
            }
            return -1;
        }


    }

}

public class Main {


     int contarCapas (TreeSet<punto> puntosOrdenados){

         System.out.println("asdasdf");
        int numeroDeCapas=0;

        HashSet <punto> puntosUsados = new HashSet<punto>();

        while (!puntosOrdenados.isEmpty()){

            punto p= puntosOrdenados.pollFirst();

            puntosUsados.add(p);

            //chequear contra todos los demas para hallar minArco
            double minArco=99999999;
            punto minPunto = new punto(-2001,-2001);
            double arco=0;
            for (punto siguiente: puntosOrdenados){

                if(siguiente.equals(p)){
                    continue;
                }


                arco=Math.atan2(p.y - siguiente.y, p.x - siguiente.x);
                if (arco< minArco){
                    minArco=arco;
                    minPunto = siguiente;
                }

            }

            if (puntosUsados.contains(minPunto)){

                numeroDeCapas= numeroDeCapas+1;

            }

        }

        return numeroDeCapas;

    }



    public static void main(String[] args) {

        PointComparator pointComparator = new PointComparator();

        System.out.println(Math.atan2(-1.0, 1.0));
        //System.out.println(Math.acos(cont))
        Scanner s = new Scanner(System.in);

        try{
        s = new Scanner(new File("entrada.txt"));
        } catch(IOException e){}
        int N,x,y;

        N = s.nextInt();

        while(N!=0){

            punto cebolla[] = new punto[N];

            TreeSet <punto> puntosOrdenados = new TreeSet <punto>(pointComparator);

            for(int i=0;i<N;i++){
                x=s.nextInt(); y=s.nextInt();
                cebolla[i]=new punto(x,y); //borrar?
                puntosOrdenados.add(new punto(x,y));
            }

           Main m = new Main();
           int cont= m.contarCapas(puntosOrdenados);
           System.out.println(cont);

             if(cont%2==0){
                System.out.println("NO");
             }else{
                System.out.println("SI");
             }
             N = s.nextInt();
        }
    }


    }

That gibbering println inside contarCapas isn't printing. The code isn't entering its call. Why?

Upvotes: 0

Views: 508

Answers (1)

Ryan Stewart
Ryan Stewart

Reputation: 128899

That's what I'd expect to see if your source is out of sync with the bytecode that's running. Try a clean build of the code, or you could also use javap to disassemble the bytecode and see if it looks like it matches the source, depending on your situation.

Upvotes: 2

Related Questions