Android-毕加索中未加载图像
我试图从在线数据库中获取一些图像URL,并在毕加索画廊中展示它们。我的问题是我的图像没有加载。我得到图像的边框,但它们是空的(没有显示任何内容) 以下是我目前的代码: main活动Android-毕加索中未加载图像,android,Android,我试图从在线数据库中获取一些图像URL,并在毕加索画廊中展示它们。我的问题是我的图像没有加载。我得到图像的边框,但它们是空的(没有显示任何内容) 以下是我目前的代码: main活动 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gridView1 = (GridVi
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gridView1 = (GridView) findViewById(R.id.gridview);
image_urls = new ArrayList<>();
if (gridView1.getChildCount() != 0 || image_urls != null) {
gridView1.setAdapter(null);
}
if (image_urls.isEmpty()) {
getImages();
}
}
// getting the image URLs from database
protected void showList() {
try {
JSONObject jsonObj = new JSONObject(myJSON);
photos = jsonObj.getJSONArray(TAG_RESULTS);
for (int i = 0; i < photos.length(); i++) {
JSONObject c = photos.getJSONObject(i);
String email_user = c.getString(TAG_EMAIL_USER);
String poi_name = c.getString(TAG_POI_NAME);
String photo_url = c.getString(TAG_PHOTO_URL);
if (poi_name.contains(map.markerdesc) && photo_url!=null) {
// add to the picasso gallery
photo_url="http://xxxxx.ro/poi/photos/"+photo_url;
image_urls.add(photo_url);
}
}
final ImageAdapter adapter = new ImageAdapter(this);
adapter.notifyDataSetChanged();
gridView1.setAdapter(adapter);
gridView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(poi_photos.this, ImageActivity.class);
intent.putExtra("url", adapter.imageUrls.get(position));
startActivity(intent);
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
public void getImages() {
class GetDataJSON extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://xxxxxx.ro/poi/table_photo_out.php");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
// Oops
} finally {
try {
if (inputStream != null) inputStream.close();
} catch (Exception squish) {
}
}
return result;
}
@Override
protected void onPostExecute(String result) {
myJSON = result;
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
}
public class ImageActivity extends Activity {
private Target target;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
final ImageView image = (ImageView) findViewById(R.id.image);
target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
image.setImageBitmap(bitmap);
int defaultColor = getResources().getColor(R.color.Blonde);
toolbar.setBackgroundColor(palette.getLightVibrantColor(defaultColor));
toolbar.setTitleTextColor(palette.getDarkMutedColor(defaultColor));
toolbar.setTitle(getString(R.string.app_name));
}
});
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.with(this)
.load(getIntent().getStringExtra("url"))
.into(target);
}
}
你知道这里有什么问题吗?
我使用的是毕加索图书馆2.5.2版
任何帮助都将不胜感激
编辑:
我发现,如果我使用字符串数组而不是arraylist(不知道为什么),它是有效的,但只有当我向它发送如下URL时,它才有效:
public String[] imageUrls = {
"http://forum.wexphotographic.com/pictures%5Cbaby%20owl.jpg",
"https://s-media-cache-ak0.pinimg.com/236x/db/b2/4f/dbb24f70f9e9f6d95e0e103e5b5f16f7.jpg",
"http://imgs.abduzeedo.com/files/articles/baby-animals/Baby-Animals-011.jpg",
"https://s-media-cache-ak0.pinimg.com/236x/04/c6/3d/04c63d072e52affb09f4549298b754e6.jpg",
"https://s-media-cache-ak0.pinimg.com/736x/4a/65/e1/4a65e1f4d7c72ecca33b01ce3306964f.jpg",
"http://pcwallart.com/images/cute-golden-retriever-puppies-wallpaper-1.jpg",
};
如果我将arrayList转换为字符串数组,我的照片也不会上传
public String[] imageUrls = poi_photos.image_urls.toArray(new String[poi_photos.image_urls.size()]);
EDIT2:
发现我的问题所在…我发送的URL不正确…其中一些包含空格,因此我修改了此部分:
public void updateWith(String imageUrl) {
imageUrl = imageUrl.replace(" ", "%20");
Picasso.with(context)
.load(imageUrl)
.placeholder(R.drawable.rectangle)
.resize(getItemWidth(), getItemWidth())
.centerCrop()
.into(imageView);
}
现在它工作得很好 我有类似的问题,但还没有解决。图像在50%的时间内都没有加载,但提供了url。您可以做的跟踪错误的一件事是将图像加载到
目标
而不是直接加载到图像视图
,这样您就可以对错误进行回调,您可以调试并检查是否打印了getIntent().getStringExtra(“url”)
为了确保url数据没有损坏?我发现了问题所在…它涉及到我如何发送url(其中一些url包含空格,因此我将它们全部替换为“%20”),现在它可以正常工作了。感谢您的所有建议!使用它来解码java中的URL…urldecover.decode(stingvalue,“UTF-8”);我有类似的问题,但还没有解决。图像在50%的时间内都没有加载,但提供了url。您可以做的跟踪错误的一件事是将图像加载到目标
而不是直接加载到图像视图
,这样您就可以对错误进行回调,您可以调试并检查是否打印了getIntent().getStringExtra(“url”)
为了确保url数据没有损坏?我发现了问题所在…它涉及到我如何发送url(其中一些url包含空格,因此我将它们全部替换为“%20”),现在它可以正常工作了。感谢您的所有建议!使用它来解码java中的URL…urldecover.decode(stingvalue,“UTF-8”);
public void updateWith(String imageUrl) {
imageUrl = imageUrl.replace(" ", "%20");
Picasso.with(context)
.load(imageUrl)
.placeholder(R.drawable.rectangle)
.resize(getItemWidth(), getItemWidth())
.centerCrop()
.into(imageView);
}