android arrayLIST of objects ksoap does not fill my listview

1

I am developing an app that consumes webservices, the detail is that they send me a method called menu , which returns me an xml, I am implementing the class Asynctask and in the part of Ibackgrind I make the call to my webservices and I save it in an array, but then in the onpostexecute it fills my lisview , only that at the moment it finishes bringing me the data it thunders does not happen to the onpostexecute method, I leave the console error :

  

04-21 14: 46: 38.645 18977-18977 / com.example.onc_lap.project I / art: Not   late-enabling -Xcheck: jni (already on) 04-21 14: 46: 38.771   18977-18977 / com.example.onc_lap.proyecto W / System: ClassLoader   referenced unknown path:   /data/app/com.example.onc_lap.proyecto-1/lib/x86 04-21 14: 46: 38.798   18977-18990 / com.example.onc_lap.proyecto D / OpenGLRenderer: Use   EGL_SWAP_BEHAVIOR_PRESERVED: true 04-21 14: 46: 38.923   18977-18990 / com.example.onc_lap.proyecto I / OpenGLRenderer: Initialized   EGL, version 1.4 04-21 14: 46: 39.002   18977-18990 / com.example.onc_lap.proyecto W / EGL_emulation:   eglSurfaceAttrib not implemented 04-21 14: 46: 39.002   18977-18990 / com.example.onc_lap.proyecto W / OpenGLRenderer: Failed to   set EGL_SWAP_BEHAVIOR on surface 0xabdc6dc0, error = EGL_SUCCESS 04-21   14: 46: 50.246 18977-18983 / com.example.onc_lap.proyecto W / art:   Suspending all threads took: 41.574ms 04-21 14: 46: 50.261   18977-18977 / com.example.onc_lap.proyecto D / AndroidRuntime: Shutting   down VM 04-21 14: 46: 50.261 18977-18977 / com.example.onc_lap.proyecto   E / AndroidRuntime: FATAL EXCEPTION: main                                                                                 Process: com.example.onc_lap.proyecto, PID: 18977                                                                                 java.lang.NullPointerException: Attempt to invoke virtual method 'void   android.app.ProgressDialog.dismiss () 'on a null object reference                                                                                     at   com.example.onc_lap.proyecto.menu $ AsyncCallWSMenu.onPostExecute (menu.java:86)                                                                                     at   com.example.onc_lap.proyecto.menu $ AsyncCallWSMenu.onPostExecute (menu.java:52)                                                                                     at android.os.AsyncTask.finish (AsyncTask.java:651)                                                                                     at android.os.AsyncTask.-wrap1 (AsyncTask.java)                                                                                     at   android.os.AsyncTask $ InternalHandler.handleMessage (AsyncTask.java:668)                                                                                     at android.os.Handler.dispatchMessage (Handler.java:102)                                                                                     at android.os.Looper.loop (Looper.java:148)                                                                                     at android.app.ActivityThread.main (ActivityThread.java:5417)                                                                                     at java.lang.reflect.Method.invoke (Native Method)                                                                                     at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:726)                                                                                     at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616) 04-21   14: 47: 33.805 18977-18977 / com.example.onc_lap.project I / Process:   Sending signal. PID: 18977 SIG: 9

activiy code:

package com.example.onc_lap.proyecto;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ONC-LAP on 19/04/2016.
 */
public class menu extends Activity {

    Button btnmenu;
    String ResultMenu;
    ProgressDialog dialog;
    ListView list;

    ArrayAdapter<String>  arrayadapter;
    ArrayList MenuArrayList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu);

        list=(ListView)findViewById(R.id.listmenu);

        btnmenu = (Button) findViewById(R.id.btnmenu);
        btnmenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                AsyncCallWSMenu task = new AsyncCallWSMenu();
                //Call execute
                task.execute();

            }
        });
        {

        }

    }

    private class AsyncCallWSMenu extends AsyncTask<String, ArrayList, menuxml> {

        List<String> arraylist = new ArrayList<String>();

        @Override
        protected menuxml doInBackground(String... params)         {
            MenuArrayList=webService.Menu();
            menuxml n = new menuxml();
            return n;
        }

        @Override
        //Make Progress Bar visible
        protected void onPreExecute() {
/*
            dialog=new ProgressDialog(menu.this);
            dialog.setIndeterminate(false);
            dialog.setMessage("Loding...");
            dialog.setCancelable(false);
            dialog.show();
*/
        }

        protected void onProgressUpdate(String... params) {
        }


        //Once WebService returns response
        protected void onPostExecute(menuxml n) {


            super.onPreExecute();
            // tv.setText(displayText);
            if(MenuArrayList.size()!=0){
                dialog.dismiss();
                arrayadapter = new ArrayAdapter<String>(menu.this,
                        android.R.layout.simple_list_item_activated_1, arraylist );
                list.setAdapter(arrayadapter);
            }else{
                dialog.dismiss();

            }

        }
    }
}

webservices:

public static ArrayList Menu() {

        // Create request
        SoapObject request = new SoapObject("http://oncontrol.no-ip.net:9020/","Menu");
        // Property which holds input parameters

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.implicitTypes=false;
        // Set output SOAP object
        envelope.setOutputSoapObject(request);
        // Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,7000);

        ArrayList MenuArray = new ArrayList();
        //ArrayAdapter<String>  arrayadapter;
        try {
            androidHttpTransport.debug=true;
            // Invoke web service
            androidHttpTransport.call("http://oncontrol.no-ip.net:9020/Menu", envelope);
            String ss=androidHttpTransport.responseDump;
            // Get the response
           // SoapObject obj1 = (SoapObject) envelope.bodyIn;
           // SoapObject obj2 = (SoapObject) obj1.getProperty(0);
            SoapObject response = (SoapObject)envelope.getResponse();

            SoapObject obj1 = (SoapObject) envelope.getResponse();

            SoapObject obj2 =(SoapObject) obj1.getProperty(1);

            SoapObject obj3 =(SoapObject) obj2.getProperty(0);

            for(int i=0; i<obj3.getPropertyCount(); i++)
            {
                SoapObject obj4 =(SoapObject) obj3.getProperty(i);
                int id= Integer.parseInt(obj4.getProperty("Id").toString());
                String Descripcion = obj4.getProperty("Descripcion").toString();
                MenuArray.add(i,Descripcion);
            }

        } catch (Exception e) {
            //Assign Error Status true in static variable 'errored'
            //menu.errored = true;
            e.printStackTrace();
        }
        //Return booleam to calling object
        //return loginStatus;

        return MenuArray;
    }
}

I already modified my activity but still skips the onpostexecute I leave my code as I have already modified

    private class AsyncCallWSMenu extends AsyncTask<String, ArrayList, ArrayList> {



            @Override
            protected ArrayList doInBackground(String... params)         {
                MenuArrayList=webService.Menu();

                return "";
            }

            @Override
            //Make Progress Bar visible
            protected void onPreExecute() {
    /*
                dialog=new ProgressDialog(menu.this);
                dialog.setIndeterminate(false);
                dialog.setMessage("Loding...");
                dialog.setCancelable(false);
                dialog.show();
    */
            }

/*            @Override
            protected void onProgressUpdate(ArrayList... values) {
                super.onProgressUpdate(values);
            }*/

            //Once WebService returns response
            @Override
            protected void onPostExecute(ArrayList arrayList) {
                if (MenuArrayList.size() !=0){
                    arrayadapter = new ArrayAdapter<String>(menu.this,
                            android.R.layout.simple_list_item_activated_1, arraylist);
                    list.setAdapter(arrayadapter);
                }
            }
        }
    }
    
asked by Hugo Rodriguez 21.04.2016 в 21:53
source

1 answer

2

The main error is:

  

java.lang.NullPointerException: Attempt to invoke virtual method 'void   android.app.ProgressDialog.dismiss () 'on a null object reference at

is because you try to execute the dismiss () method on a null instance of dialog :

dialog.dismiss();

since you have commented on the creation of the ProgressDialog:

dialog=new ProgressDialog(menu.this);

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

To make your ListView have values, ensure that MenuArrayList contains data within onPostExecute() ,

   if(MenuArrayList.size()!=0){
                dialog.dismiss();
           arrayadapter = new ArrayAdapter<String>(
                 this, 
                 android.R.layout.simple_list_item_1,
                 MenuArrayList ); //* no se usa your_array_list
           list.setAdapter(arrayadapter);
            }else{
                dialog.dismiss();
            }
    
answered by 21.04.2016 / 23:21
source