在我的应用程序中,有些活动我曾经从解析服务器调用数据,但在打开任何活动后突然发生应用程序崩溃,并在重新启动应用程序后打开了
Four.java
@ParseClassName("Four")
public class Four extends ParseObject{
public Four(){
}
public String getFourc(){
return getString("fourc");
}
public void setFourc(String fourc){
put("fourc", fourc);
}
}
四个适配器
public class FourAdapter extends ArrayAdapter<Four> {
private Context mContext;
private List<Four> mFours;
public FourAdapter(Context context, List<Four> objects) {
super(context, R.layout.four_row_item, objects);
this.mContext = context;
this.mFours = objects;
}
public View getView(int position, View convertView, ViewGroup parent){
if(convertView == null){
LayoutInflater mLayoutInflater = LayoutInflater.from(mContext);
convertView = mLayoutInflater.inflate(R.layout.four_row_item, null);
}
Four four = mFours.get(position);
TextView descriptionView = (TextView) convertView.findViewById(R.id.four_fourc);
descriptionView.setText(four.getFourc());
return convertView;
}
}
FourActivity
public class FourActivity extends AppCompatActivity {
private ListView mListView;
private FourAdapter mAdapter;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_four);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setIcon(R.drawable.gpsicon);
mAdapter = new FourAdapter(this, new ArrayList<Four>());
progressBar = (ProgressBar) findViewById(R.id.loading);
mListView = (ListView) findViewById(R.id.four_list);
mListView.setAdapter(mAdapter);
ParseQuery<Four> query = ParseQuery.getQuery(Four.class);
query.findInBackground(new FindCallback<Four>() {
public void done(List<Four> fours, ParseException error) {
if (fours != null) {
mAdapter.clear();
progressBar.setVisibility(View.GONE);
for (int i = 0; i < fours.size(); i++) {
mAdapter.add(fours.get(i));
}
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_four, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_notice) {
Intent i = new Intent(this, FonActivity.class);
startActivity(i);
return true;
}
if (id == R.id.home) {
this.finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
LogCat错误
09-23 23:07:11.776 2400-2400/com.school.gurunanakpublicschool E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ClassCastException: com.parse.ParseObject cannot be cast to com.school.gurunanakpublicschool.Four
at com.school.gurunanakpublicschool.FourAdapter.getView(FourAdapter.java:29)
at android.widget.AbsListView.obtainView(AbsListView.java:2177)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1247)
at android.widget.ListView.onMeasure(ListView.java:1159)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:124)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:444)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
at android.view.View.measure(View.java:15848)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
App在任何活动中随机崩溃,还有更多此类活动请帮帮我。