我在使用AsyncTask在我的应用程序中显示listview时遇到问题,这是我的代码
Public class Propiedades extends Fragment{
//URL to get JSON Array
private static String url = "http://10.72.13.88/TestCon/buscar.php";
//JSON Node Names
private static final String TAG_PROPIEDAD = "estado";
private static final String TAG_ID = "idPropiedad";
private static final String TAG_NAME = "nombreReparto";
private static final String TAG_DESC = "descripcionEspaniol";
private static final String TAG_IMAGE = "image";
private static final String TAG_IMG = "imagen";
AdaptadorProp adapter;
private PropiedadList[] datos;
private MiTareaAsincrona tarea1;
private ListView lstListado;
JSONArray user=null;
JSONArray ruta=null;
JSONObject c = null;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.propiedades, container, false);
tarea1 = new MiTareaAsincrona();
tarea1.execute();
return rootView;
}
@Override
public void onActivityCreated(Bundle state) {
super.onActivityCreated(state);
lstListado = (ListView)getView().findViewById(R.id.LstListado);
lstListado.setAdapter(new AdaptadorProp(this));
/*lstListado.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> list, View view, int pos, long id) {
if (listener!=null) {
listener.onCorreoSeleccionado(
(Correo)lstListado.getAdapter().getItem(pos));
}
}
});*/
}
class AdaptadorProp extends ArrayAdapter<PropiedadList> {
Activity context;
AdaptadorProp(Fragment context) {
super(context.getActivity(), R.layout.list_propiedad, datos);
this.context = context.getActivity();
System.out.println(datos);
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View item = inflater.inflate(R.layout.list_propiedad, null);
TextView lblDe = (TextView)item.findViewById(R.id.title_propiedad);
lblDe.setText(datos[position].getTitulo());
TextView lblAsunto = (TextView)item.findViewById(R.id.detalle_propiedad);
lblAsunto.setText(datos[position].getDetalle());
return(item);
}
}
private class MiTareaAsincrona extends AsyncTask<Void, Integer, PropiedadList[]> {
@Override
protected PropiedadList[] doInBackground(Void... params) {
// Creating new JSON Parser
JSONParser jParser = new JSONParser();
// Getting JSON from URL
JSONObject json =new JSONObject();
json = jParser.getJSONFromUrl(url);
//System.out.print(json);
try {
// Getting JSON Array
//JSONObject c = json.getJSONObject(TAG_USER);
user = json.getJSONArray(TAG_PROPIEDAD);
ruta = json.getJSONArray(TAG_IMAGE);
datos = new PropiedadList[user.length()];
for(int i=0;i<=user.length();i++)
{
JSONObject c = user.getJSONObject(i);
datos[i] = new PropiedadList(c.getString(TAG_NAME), c.getString(TAG_DESC), c.getString(TAG_ID));
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
//Toast.makeText(getActivity(), "Cargando!", Toast.LENGTH_SHORT).show();
}
@Override
protected void onPreExecute() {
Toast.makeText(getActivity(), "Cargando!", Toast.LENGTH_SHORT).show();
}
@Override
protected void onPostExecute(PropiedadList[] result) {
if(result!=null)
System.out.println(datos);
Toast.makeText(getActivity(), "Tarea finalizada!", Toast.LENGTH_SHORT).show();
//Toast.makeText(Propiedades.this,
}
@Override
protected void onCancelled() {
//Toast.makeText(MainActivity.this, "Tarea cancelada!", Toast.LENGTH_SHORT).show();
}
}}`
错误日志是这个
01-30 10:22:40.754: E/AndroidRuntime(13767): FATAL EXCEPTION: main
01-30 10:22:40.754: E/AndroidRuntime(13767): Process: info.androidhive.slidingmenu, PID: 13767
01-30 10:22:40.754: E/AndroidRuntime(13767): java.lang.NullPointerException: storage == null
01-30 10:22:40.754: E/AndroidRuntime(13767): at java.util.Arrays$ArrayList.<init>(Arrays.java:38)
01-30 10:22:40.754: E/AndroidRuntime(13767): at java.util.Arrays.asList(Arrays.java:155)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:128)
01-30 10:22:40.754: E/AndroidRuntime(13767): at info.androidhive.slidingmenu.Propiedades$AdaptadorProp.<init>(Propiedades.java:89)
01-30 10:22:40.754: E/AndroidRuntime(13767): at info.androidhive.slidingmenu.Propiedades.onActivityCreated(Propiedades.java:71)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.app.Fragment.performActivityCreated(Fragment.java:1708)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:908)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.app.BackStackRecord.run(BackStackRecord.java:684)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.os.Handler.handleCallback(Handler.java:733)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.os.Handler.dispatchMessage(Handler.java:95)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.os.Looper.loop(Looper.java:136)
01-30 10:22:40.754: E/AndroidRuntime(13767): at android.app.ActivityThread.main(ActivityThread.java:5081)
01-30 10:22:40.754: E/AndroidRuntime(13767): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 10:22:40.754: E/AndroidRuntime(13767): at java.lang.reflect.Method.invoke(Method.java:515)
01-30 10:22:40.754: E/AndroidRuntime(13767): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
01-30 10:22:40.754: E/AndroidRuntime(13767): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-30 10:22:40.754: E/AndroidRuntime(13767): at dalvik.system.NativeStart.main(Native Method)
我试图在使用AsyncTask之前使用我的自定义适配器AdaptadorProp显示listview应用程序工作正常但现在我有这个问题,我是新的android编程所以我不知道我有什么错误