0

I have a problem trying to use the method calcularRuta from outside an activity. The method returns a value depending on the inputs it has. I can't get any results because i tried debugging it and it doesn't even enter the method, so it when i have to use the variable ruta in the next line it's null.

public boolean onTouch(View v, MotionEvent event) {

            try {
                String qr = DecodeQR.zxing(mRgba);

                int origen = Integer.valueOf(qr);
                int destino = Integer.valueOf(bundle.getString("DESTINO"));
                boolean ascensor = bundle.getBoolean("ASCENSOR");

                if (ruta == null)
                    ruta = IniciarBusqueda.calcularRuta(origen, destino, ascensor);

                updateScreen(qr, ruta.toString());

            } catch (ChecksumException e) {
                e.printStackTrace();
            } catch (FormatException e) {
                e.printStackTrace();
            }
            return false;
        }

I'm trying to figure out what is the problem but i can't... Any thoughts?

Thanks.

EDIT: Changed the utility method to static.

Pagaza
  • 23
  • 4
  • Why don't you make that method as `public static`? And call it like `ClassName.MehodName`. – Aniruddha May 20 '14 at 08:49
  • "doesn't even enter the method" ? are you sure "IniciarBusqueda.getInstance()" is not returning null ? – Hirak May 20 '14 at 08:49
  • I tried to use it as static but it doesn't work. Also the utility class is working fine because i've used it in other works... – Pagaza May 20 '14 at 09:07

1 Answers1

0

1) You shouldn't instantiate an activity.

2) Make that method public static so that you can access it by using Classname.methodName. No need to instantiate the class.

Aniruddha
  • 4,477
  • 2
  • 21
  • 39