加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 图像显示不正确

发布时间:2020-12-15 02:35:32 所属栏目:Java 来源:网络整理
导读:我正在制作一个使用lazylist显示图像和文本的 Android应用程序. 我从服务器的json获取数据.当我手动将一些数据和图像路径输入到mysql数据库中时,这些图像会在应用程序中正确显示. 但是当我从移动摄像头拍摄图像并上传该图像时,它会在mysql数据库中正确插入路
我正在制作一个使用lazylist显示图像和文本的 Android应用程序.

我从服务器的json获取数据.当我手动将一些数据和图像路径输入到mysql数据库中时,这些图像会在应用程序中正确显示.

但是当我从移动摄像头拍摄图像并上传该图像时,它会在mysql数据库中正确插入路径,但它不会显示在我的应用程序中.

有人能告诉我为什么会遇到这个问题吗?我的logcat中没有出错.

有其他人有这个问题吗?如果是,那么你是如何解决的?请帮我.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_list);

    inboxList = new ArrayList<HashMap<String,String>>();

    List<String> profile_photo = new ArrayList<String>();
    List<String> userName = new ArrayList<String>();
    List<String> place = new ArrayList<String>();

    list=(ListView)findViewById(R.id.list);
    //adapter=new LazyAdapter(this,tS,mTitles);
    list.setAdapter(adapter);

    /********************************/

    JSONObject json = userFunctions.homeData();

    Log.e("Data",json.toString());

    // Check your log cat for JSON reponse
    // Log.d("Inbox JSON: ",json.toString());

    try {
        data = json.getJSONArray("data");
        Log.d("inbox array: ",data.toString());
        // looping through All messages
        for (int i = 0; i < data.length(); i++) {
            JSONObject c = data.getJSONObject(i);

            // Storing each json item in variable
            String uid = c.getString("uid");
            String name = c.getString("name");
            String success = c.getString("success");
            String profile_img = c.getString("profile_photo");
            //String date = c.getString(TAG_DATE);

            JSONObject places = c.getJSONObject(TAG_PLACES);
            String place_photo = places.getString(TAG_PLACE_IMG);

            Log.e("place_photo",place_photo);
            // creating new HashMap
            HashMap<String,String> map = new HashMap<String,String>();

            // adding each child node to HashMap key => value
            map.put("uid",uid);
            map.put("name",name);
            map.put("success",success);
            map.put("profile_image",profile_img);

            profile_photo.add(profile_img);
            userName.add(name);
            place.add(place_photo);
            // adding HashList to ArrayList
            inboxList.add(map);
        }

        profile_image = new String[profile_photo.size()];
        user_name = new String[userName.size()];
        place_image = new String[(place.size())];

        profile_photo.toArray(profile_image);
        userName.toArray(user_name);
        place.toArray(place_image);
        adapter = new LazyAdapter(this,profile_image,user_name,place_image);
        list.setAdapter(adapter);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    /*******************************/
}

这是懒惰的适配器类

public class LazyAdapter extends BaseAdapter {

private Activity activity;
private String[] data;
private String[] name;
private String[] place_photo;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public LazyAdapter(Activity a,String[] d,String[] username,String[] place_image) {
    activity = a;
    data = d;
    name = username;
    place_photo = place_image;
    //Log.e("path",d.toString());
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());
}

public int getCount() {
    return data.length;
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

public View getView(int position,View convertView,ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.home_list_item,null);

    //TextView text=(TextView)vi.findViewById(R.id.text);
    TextView title = (TextView)vi.findViewById(R.id.username);
    ImageView image=(ImageView)vi.findViewById(R.id.image);
    ImageView place=(ImageView)vi.findViewById(R.id.place);
    //text.setText("item "+position);
    title.setText(name[position]);
    imageLoader.DisplayImage(data[position],image);
    imageLoader.DisplayImage(place_photo[position],place);
    return vi;
}
}

解决方法

But when I take image from mobile camera and upload that image,it does insert all the path properly in mysql database but it is still not shown in my app

新图像和旧图像的URL是否相同?

如果是这样,则可能是图像缓存的情况. ImageLoader使用URL作为密钥缓存图像….清除App数据后再试一次.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读