-1

When I pass arg this way everything works:

new MerrTeDhenatEDegeve().execute("https://navigator.bkt.com.al/bktnavigator/al/deget/al_ilamre_deget.php");

When I pass arg this way it crashes:

sh_d sh_d_instance = new sh_d();

new MerrTeDhenatEDegeve().execute(new String(sh_d_instance.deshifro(url_Deget)));

this is my async class:

class MerrTeDhenatEDegeve extends AsyncTask<String, String, String> {

    // Marrja e te dhenave te degeve
    protected String doInBackground(String... args) {

        // Ketu po krijojme parametrat qe do te na duhet per te krijuar querin ne db
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        // Ketu po bejme kerkesen per tek serveri dhe presim te marrim pergjigjen e json ne string
        JSONObject jsonDega = jParserDega.makeHttpRequest(args[0], "GET", params);

        try {
            // Si fillim kontrollojme nqs kemi sukses ne marrjen e te dhenave apo jo
            int sukses = jsonDega.getInt(TAG_SUKSES);

            if (sukses == 1) {
                // Ne rast suksesi atehere dmth qe kemi marre te dhenat e degeve dhe fillojme qe ti vendosim ato ne listat perkatese te tyre
                Deget = jsonDega.getJSONArray(TAG_DEGET);

                // Bredhim tek secili objekt me te dhenat e vektorit json dhe per secilin prej objekteve marrim vlerat qe na duhen
                for (int i = 0; i < Deget.length(); i++) {

                    JSONObject VlObj = Deget.getJSONObject(i);

                    // Rruajme te dhenat ne listat perkatese ne menyre qe pastaj ti kapim globalisht
                    listaDegaID.add(VlObj.getString(TAG_DEGE_DID));
                    listaDegaEmrave.add(VlObj.getString(TAG_DEGE_EMRI));
                    listaDegaAdresave.add(VlObj.getString(TAG_DEGE_ADRESA));
                    listaDegaQyteteve.add(VlObj.getString(TAG_DEGE_QYTETI));
                    listaDegaLat.add(VlObj.getString(TAG_DEGE_LATITUDE));
                    listaDegaLng.add(VlObj.getString(TAG_DEGE_LONGITUDE));
                    listaDegaUrlFoto1.add(VlObj.getString(TAG_DEGE_URLFOTO_1));
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }
}

So it crashes when it gets the data from another method which returns string.

Please I need help. Thank you

Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
  • what does the `deshifro()` method return? – Daniel Nugent Jun 14 '15 at 00:17
  • it returns this: "https://navigator.bkt.com.al/bktnavigator/al/deget/al_ilamre_deget.php" becuase url_Deget = "f21gdf21h3sd21h3d1h3gd" is the decrypted version of the url. the deshifro method decrypts it and returns the url. – Ermal Asllanaj Jun 14 '15 at 00:41

1 Answers1

0

Which errors are you having? Can you please post the stacktrace? It is hard to say something wihtout looking at the stack, however, I would tell you to check the result of this deshifro method. If it is returning null it is likely that you get a nullPointerException here: JSONObject jsonDega = jParserDega.makeHttpRequest(args[0], "GET", params);

E. Fernandes
  • 3,889
  • 4
  • 30
  • 48
  • i have checked deshifro and it retorns the same as this: "https://navigator.bkt.com.al/bktnavigator/al/deget/al_ilamre_deget.php" – Ermal Asllanaj Jun 14 '15 at 00:17
  • It doesnt show any error it runs ok, but when the async is started from the main activity it crashes – Ermal Asllanaj Jun 14 '15 at 00:18
  • When it crashes it does't throws any error? It has to! Something crased the app, it needs to display something. If you are using AS it might happen that the logcat removes the filter to your app once it crashes, but try to look at the stack for errors anyways. By any chance are you trying to change something in the layout from inside the doInBackground method? If yes the app will crash because only the main thread might cause layout changes. – E. Fernandes Jun 14 '15 at 00:21
  • it gives me this error on console: [2015-06-14 01:17:45 - ddms] null java.nio.BufferOverflowException at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:200) at com.android.ddmlib.JdwpPacket.movePacket(JdwpPacket.java:235) at com.android.ddmlib.Debugger.sendAndConsume(Debugger.java:347) at com.android.ddmlib.Client.forwardPacketToDebugger(Client.java:698) at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:344) at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263) – Ermal Asllanaj Jun 14 '15 at 00:23
  • what i am trying is to decrypt the encrypted version of that url and pass it to the asyncttask. the method that makes the decyption is "deshifro". When i see the output of deshifro on Toast msg it works fine. – Ermal Asllanaj Jun 14 '15 at 00:24
  • "(...) A BufferOverflowException is thrown when elements are written to a buffer but there is not enough remaining space in the buffer..." your problem has nothing to do with passing data to the AsyncTask. At some line of the code inside the doInBackground you're trying to fill a buffer but there is no more space on it. I would say that it has something to do with thisline: Deget = jsonDega.getJSONArray(TAG_DEGET); it looks wrong to me, if Deget is a class where is the reference variable? How is this even compiling? – E. Fernandes Jun 14 '15 at 00:32
  • Deget is a JSONArray with JSONObjcet which i get from the url. If you click on the url you will see a json format response from server. If it isnt the problem with the passing of variables to asynctask, why it is working when i pass as a string. The only thing that remains to is that asynctask is executed before the new String(sh_d_instance.deshifro(url_Deget)) – Ermal Asllanaj Jun 14 '15 at 00:39
  • Now I see that you have used the Deget.length in the for loop. Having variables with starting uppercase letters is bad practive, only classes and interfaces should start with capital letters. Anyways, I still say that the problem isn't with the data passage. Are you sure that Deget has enought room for the result that you are asigning to it? After decripting the URL you might get a different answert from what you are getting when passing it straight – E. Fernandes Jun 14 '15 at 00:44
  • how can i find out if i am getting deferent result after decrypting the url? – Ermal Asllanaj Jun 14 '15 at 00:48
  • check out the content of Deget (its size for instance) when passing the URL straight and after decrypting it – E. Fernandes Jun 14 '15 at 00:49
  • 06-14 10:58:44.628: E/AndroidRuntime(28346): Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 70: https://navigator.bkt.com.al/bktnavigator/al/deget/al_ilamre_deget.php��������������������? – Ermal Asllanaj Jun 14 '15 at 09:01
  • it looks like after decrypting some special character that your JVM is not prepared to read is coming. – E. Fernandes Jun 14 '15 at 15:37
  • Can you please tell me how can i handle this problem, cause when i put the output of deshifro on a edit text it show the right url. – Ermal Asllanaj Jun 17 '15 at 19:45