2012-04-20 67 views
0

我正在开发一个android应用程序,其中包含listview与图像,webviews,我们在日常应用程序中使用的许多常见视图。我的应用程序正常工作,但是当我运行它3到4次时,它从当前活动突然崩溃并转到上一次。我不知道为什么。它不会给出任何例外或错误。然后我再次启动该活动3到4次,然后再次崩溃。有人告诉我为什么会发生。可能是内存管理。在Android中突然发生的活动崩溃

主要它在listview活动中崩溃。但如果它使用listview上的数据加载而崩溃,它必须给出一个例外。我也使用线程,图像加载器,视图。但是找不到什么概率!

适配器的ListView的是:

public class SavedAdapter extends BaseAdapter { 

Context context; 
JSONArray jsonArraySaved; 
JSONObject jsonObjectSaved; 
String user_id = "", distance = ""; 

public SavedAdapter(Context context, JSONArray jsonArraySaved) { 
    this.context = context; 
    this.jsonArraySaved = jsonArraySaved;  
} 

@Override 
public int getCount() { 
    // TODO Auto-generated method stub 
    return jsonArraySaved.length(); 
} 

@Override 
public JSONObject getItem(int position) { 
    // TODO Auto-generated method stub 
    try { 
     return jsonArraySaved.getJSONObject(position); 
    } catch (JSONException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     return null; 
    } 
} 

@Override 
public long getItemId(int position) { 
    // TODO Auto-generated method stub 
    return 0; 
} 

public static class ViewHolder { 
    public GothicBoldTextView textViewFullName, textViewDistance; 
    public GothicTextView textViewHeadLine, textViewTags; 
    public ImageView imageViewPhoto;   
} 

@Override 
public View getView(final int position, View rawView, ViewGroup parent) { 
    // TODO Auto-generated method stub  
    ViewHolder viewHolder; 
    if (rawView == null) { 
     rawView = LayoutInflater.from(context).inflate(
       R.layout.featured_events_list_item3, null); 
     viewHolder = new ViewHolder(); 
     viewHolder.textViewFullName = (GothicBoldTextView) rawView 
       .findViewById(R.id.textViewFullName); 
     viewHolder.textViewHeadLine = (GothicTextView) rawView 
       .findViewById(R.id.textViewHeadLine); 
     viewHolder.textViewTags = (GothicTextView) rawView 
       .findViewById(R.id.textViewTags); 
     viewHolder.textViewDistance = (GothicBoldTextView) rawView 
       .findViewById(R.id.textViewDistance); 
     viewHolder.imageViewPhoto = (ImageView) rawView 
       .findViewById(R.id.imageViewPhoto); 
     rawView.setTag(viewHolder); 
    } else { 
     viewHolder = (ViewHolder) rawView.getTag(); 
    } 
    try { 
     jsonObjectSaved = getItem(position); 
     if (jsonObjectSaved.has("distance")) { 
      distance = jsonObjectSaved.getString("distance"); 
      viewHolder.textViewDistance.setText(AccessClass 
        .getDistance(distance)); 
     } 
     if (jsonObjectSaved.has("profile")) { 
      jsonObjectSaved = jsonObjectSaved.getJSONObject("profile"); 
      if (jsonObjectSaved.has("firstname")) 
       viewHolder.textViewFullName.setText(jsonObjectSaved 
         .getString("firstname")); 
      if (jsonObjectSaved.has("lastname")) 
       viewHolder.textViewFullName 
         .setText(viewHolder.textViewFullName.getText() 
           + " " 
           + jsonObjectSaved.getString("lastname")); 
      if (jsonObjectSaved.has("headline")) 
       viewHolder.textViewHeadLine.setText(jsonObjectSaved 
         .getString("headline")); 
      if (jsonObjectSaved.has("tags")) { 
       String tags = ""; 
       for (int i = 0; i < jsonObjectSaved.getJSONArray("tags") 
         .length(); i++) { 
        tags += jsonObjectSaved.getJSONArray("tags") 
          .getJSONObject(i).getString("name") 
          + ", "; 
       } 
       viewHolder.textViewTags.setText(tags.substring(0, 
         tags.length() - 2)); 
      } 
      if (jsonObjectSaved.has("avatar_thumb")) { 

       if (!jsonObjectSaved.getString("avatar_thumb").equals(
         "/avatars/thumb/missing.png")) { 
        viewHolder.imageViewPhoto.setTag(jsonObjectSaved 
          .getString("avatar_thumb")); 
        SplashActivity.imageLoader.displayImage(context 
          .getResources().getString(R.string.domain) 
          + jsonObjectSaved.getString("avatar_thumb"),         
          viewHolder.imageViewPhoto); 

       } else if (!jsonObjectSaved.isNull("picture_url")) {        
        viewHolder.imageViewPhoto.setTag(jsonObjectSaved 
          .getString("picture_url")); 
        SplashActivity.imageLoader.displayImage(
          jsonObjectSaved.getString("picture_url"),        
          viewHolder.imageViewPhoto); 
       } 
      } else if (jsonObjectSaved.has("picture_url") 
        && !jsonObjectSaved.isNull("picture_url")) {      
       viewHolder.imageViewPhoto.setTag(jsonObjectSaved 
         .getString("picture_url")); 
       SplashActivity.imageLoader.displayImage(
         jsonObjectSaved.getString("picture_url"),       
         viewHolder.imageViewPhoto); 
      } else {      
       viewHolder.imageViewPhoto.setTag("null"); 
       viewHolder.imageViewPhoto.setImageResource(R.drawable.photo2); 
      } 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    rawView.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      try { 
       Intent intent; 
       intent = new Intent(context, PublicProfileActivity.class); 
       intent.putExtra("public_profile_id", "" 
         + getItem(position).getString("id")); 
       context.startActivity(intent); 
      } catch (Exception e) { 
       // TODO: handle exception 
       e.printStackTrace(); 
      } 
     } 
    }); 
    rawView.invalidate(); 
    return rawView; 
} 
} 
+0

这是非常困难的没有更多的信息回答。你能显示你认为有问题的代码吗?描述你做了什么来追查它? – 2012-04-21 13:49:20

+0

感谢您的回复。我已经提到了我的listview的适配器代码。但它工作正常。 – vajapravin 2012-04-23 05:04:51

+0

发布崩溃的logcat。 – 2012-06-12 18:01:14

回答

0

我想你可能

adapter.imageLoader.clearCache(); 
adapter.imageLoader.stopThread(); 
listView.setAdapter(null); 
+0

感谢您的回复,我会检查您的代码。 – vajapravin 2012-10-23 05:58:26