Estoy desarrollando una app que consume webservices, el detalle es que me mandan un metodo que se llama menu
, el cual me reponde un xml, estoy implementando la class Asynctask
y en la parte del Ibackgrind
hago el llamado a mi webservices y lo guardo en un array, pero despues en el onpostexecute
llena mi lisview
, solo que al momento en que termina de traerme los datos truena no pasa al metodo del onpostexecute
, les dejo el error de consola:
04-21 14:46:38.645 18977-18977/com.example.onc_lap.proyecto 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.proyecto I/Process: Sending signal. PID: 18977 SIG: 9
codigo activiy:
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;
}
}
ya modifique mi activity pero aun asi se salta el onpostexecute dejo mi codigo como lo tengo ya modificado
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);
}
}
}
}