我花了三天时间来处理这个错误,但仍然无法理解为什么会这样。
在我的片段onCreateview
中,我称之为asynctask:
new GetAcceptedMeetings().execute();
GetAcceptedMeetings:
private class GetAcceptedMeetings extends AsyncTask<String, String, String> {
int shortAnimTime = getResources().getInteger(
android.R.integer.config_shortAnimTime);
@Override
protected void onPreExecute() {
super.onPreExecute();
acceptedLv.setVisibility(View.GONE);
LoadStatusView.setVisibility(View.VISIBLE);
LoadStatusView.animate().setDuration(shortAnimTime)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
LoadStatusView.setVisibility(View.VISIBLE);
}
});
}
@Override
protected String doInBackground(String... params) {
List<NameValuePair> meetingparams = new ArrayList<NameValuePair>();
meetingparams.add(new BasicNameValuePair("attendant[user_id]",
Userid));
// Getting JSON string from URL
JSONObject meetingjson = jParser.makeHttpRequest(
str_url_getmeeting, "POST", meetingparams);
// Check your log cat for JSON response
Log.d("user's meeting: ", meetingjson.toString());
try {
if (meetingjson.getInt("msg") == 1) {
JSONArray meetings = meetingjson.getJSONArray("meeting");
arrMeetings.clear();
for (int i = 0; i < meetings.length(); i++) {
JSONObject c = meetings.getJSONObject(i);
String strRole = c.getString("role_id");
if (strRole.equals("1")) {
String strId = c.getString(mtTAG_MEETINGID);
String strName = c.getString(mtTAG_MEETINGNAME);
String strContent = c.getString(mtTAG_CONTENT);
String[] strDateTime = c.getString(mtTAG_DATE)
.split("T");
String strDuration = c.getString(mtTAG_DURATION);
String strLocation = c.getString(mtTAG_LOCATION);
String strCoordinate = c
.getString(mtTAG_COORDINATE);
HashMap<String, String> map = new HashMap<String, String>();
map.put(mtTAG_MEETINGID, strId);
map.put(mtTAG_MEETINGNAME, strName);
map.put(mtTAG_CONTENT, strContent);
map.put(mtTAG_DATE, strDateTime[0]);
map.put(mtTAG_TIME,
strDateTime[1].substring(0,
strDateTime[1].length() - 5));
map.put(mtTAG_DURATION, strDuration);
map.put(mtTAG_LOCATION, strLocation);
map.put(mtTAG_COORDINATE, strCoordinate);
Calendar cal = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat(
"yyyy-MM-dd");
String formattedDate = df.format(cal.getTime());
Date inputDate = df.parse(strDateTime[0]);
Log.d("Date", inputDate.toString());
Date currentDate = df.parse(formattedDate);
String status = "";
if (inputDate.compareTo(currentDate) == 0){
if(inputDate.before(currentDate))
status = "Today";
else if(inputDate.after(currentDate))
status = "Done";
}
else if (inputDate.compareTo(currentDate) < 0)
status = "Done";
else if (inputDate.compareTo(currentDate) > 0)
status = "Incoming";
map.put(mtTAG_MEETINGSTATUS, status);
arrMeetings.add(map);
}
}
Log.d("arrMeetings: ", arrMeetings.toString());
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
LoadStatusView.setVisibility(View.GONE);
adapter = new SimpleAdapter(
// Updating listview
getActivity(), arrMeetings, R.layout.meeting_item,
new String[] { mtTAG_MEETINGNAME, mtTAG_DATE, mtTAG_TIME,
mtTAG_LOCATION, mtTAG_MEETINGSTATUS },
new int[] { R.id.txtTitleMeeting,
R.id.txtDatetime,
R.id.txtTime,
R.id.txtLocation,
R.id.txtStatusMeeting }) {
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
View v = convertView;
for (int i = 0; i < arrMeetings.size(); i++) {
LayoutInflater vi = (LayoutInflater) getActivity()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.meeting_item, null);
TextView txtTitleMeeting = (TextView) v
.findViewById(R.id.txtTitleMeeting);
TextView txtDatetime = (TextView) v
.findViewById(R.id.txtDatetime);
TextView txtTime = (TextView) v
.findViewById(R.id.txtTime);
TextView txtLocation = (TextView) v
.findViewById(R.id.txtLocation);
TextView txtStatusMeeting = (TextView) v
.findViewById(R.id.txtStatusMeeting);
txtTitleMeeting.setText(arrMeetings.get(position).get(
mtTAG_MEETINGNAME));
txtDatetime.setText(arrMeetings.get(position).get(
mtTAG_DATE));
txtTime.setText(arrMeetings.get(position).get(
mtTAG_TIME));
txtLocation.setText(arrMeetings.get(position).get(
mtTAG_LOCATION));
if (arrMeetings.get(position).get(mtTAG_MEETINGSTATUS)
.equals("Today")) {
txtStatusMeeting.setText(arrMeetings.get(position)
.get(mtTAG_MEETINGSTATUS));
txtStatusMeeting.setTextColor(getActivity()
.getResources().getColor(R.color.Today));
} else if (arrMeetings.get(position)
.get(mtTAG_MEETINGSTATUS).equals("Incoming")) {
txtStatusMeeting.setText(arrMeetings.get(position)
.get(mtTAG_MEETINGSTATUS));
txtStatusMeeting.setTextColor(getActivity()
.getResources().getColor(R.color.Incoming));
} else if (arrMeetings.get(position)
.get(mtTAG_MEETINGSTATUS).equals("Done")) {
txtStatusMeeting.setText(arrMeetings.get(position)
.get(mtTAG_MEETINGSTATUS));
txtStatusMeeting.setTextColor(getActivity()
.getResources().getColor(R.color.Done));
}
}
return v;
}
};
Log.d("arrMeeting Onpost:", arrMeetings.toString());
if (adapter.isEmpty()) {
txtNomeeting.setHint("You have no meeting created");
} else
txtNomeeting.setVisibility(View.GONE);
acceptedLv.setAdapter(adapter);
acceptedLv.setVisibility(View.VISIBLE);
acceptedLv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v,
int position, long id) {
//code click event here
});
}
}
我第一次打电话给这个标签时运行良好。但是当我重新加载它时,我在adapter = new SimpleAdapter
这就是logcat show
05-17 11:13:24.053: W/dalvikvm(4284): threadid=1: thread exiting with uncaught exception (group=0xa4b7d648)
05-17 11:13:24.053: E/AndroidRuntime(4284): FATAL EXCEPTION: main
05-17 11:13:24.053: E/AndroidRuntime(4284): java.lang.NullPointerException
05-17 11:13:24.053: E/AndroidRuntime(4284): at android.widget.SimpleAdapter.<init>(SimpleAdapter.java:85)
05-17 11:13:24.053: E/AndroidRuntime(4284): at info.android.mh.fragment.Tabview_Accepted_Meeting_Fragment$GetAcceptedMeetings$2.<init>(Tabview_Accepted_Meeting_Fragment.java:234)
05-17 11:13:24.053: E/AndroidRuntime(4284): at info.android.mh.fragment.Tabview_Accepted_Meeting_Fragment$GetAcceptedMeetings.onPostExecute(Tabview_Accepted_Meeting_Fragment.java:243)
05-17 11:13:24.053: E/AndroidRuntime(4284): at info.android.mh.fragment.Tabview_Accepted_Meeting_Fragment$GetAcceptedMeetings.onPostExecute(Tabview_Accepted_Meeting_Fragment.java:1)
05-17 11:13:24.053: E/AndroidRuntime(4284): at android.os.AsyncTask.finish(AsyncTask.java:631)
05-17 11:13:24.053: E/AndroidRuntime(4284): at android.os.AsyncTask.access$600(AsyncTask.java:177)
05-17 11:13:24.053: E/AndroidRuntime(4284): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
05-17 11:13:24.053: E/AndroidRuntime(4284): at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 11:13:24.053: E/AndroidRuntime(4284): at android.os.Looper.loop(Looper.java:137)
05-17 11:13:24.053: E/AndroidRuntime(4284): at android.app.ActivityThread.main(ActivityThread.java:5103)
05-17 11:13:24.053: E/AndroidRuntime(4284): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 11:13:24.053: E/AndroidRuntime(4284): at java.lang.reflect.Method.invoke(Method.java:525)
05-17 11:13:24.053: E/AndroidRuntime(4284): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
05-17 11:13:24.053: E/AndroidRuntime(4284): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-17 11:13:24.053: E/AndroidRuntime(4284): at dalvik.system.NativeStart.main(Native Method)
我真的需要尽快解决它。寻求帮助。
对不起大家,我在这里搞错了。这是一个在滑动菜单中使用片段的标签。
我修好了,很抱歉