[英]Picasso won't show image from imgur
This is the code i use, the library is imported from the jar, the image link works fine and i even added the internet permissions in the AndroidManifest.xml. 这是我使用的代码,库是从jar导入的,图像链接工作正常,我什至在AndroidManifest.xml中添加了Internet权限。 The problem is that when i start the app it opens and closes without showing anything.
问题是,当我启动该应用程序时,它打开和关闭而没有显示任何内容。
package my.pkg.name;
import com.squareup.picasso.*;
import android.R.id.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.id.immagine);
ImageView targetImageView = (ImageView) findViewById(R.id.immagine);
String internetUrl = "http://i.imgur.com/DvpvklR.png";
Picasso
.with(this)
.load(internetUrl)
.into(targetImageView);
}
}
And this is the layout 这是布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="just a string"
/>
<ImageView
android:id="@+id/immagine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="213"
/>
</LinearLayout>
Thank you 谢谢
setContentView(R.id.immagine);
is wrong. 是错的。 Usually you put
R.layout.something
into setContentView
. 通常,您将
R.layout.something
放入setContentView
。
Also, remember, except that Layout
as @eriuzo said, that could be due to Activity
: 另外,请记住,除了@eriuzo所说的
Layout
之外,这可能是由于Activity
引起的:
public class MainActivity extends Activity
For these situations, you should check the logcats if something is wrong.but, You can use that with AppCompatActivity
that should solve the problem. 对于这些情况,应该检查日志猫是否出了问题。但是,可以将其与
AppCompatActivity
一起使用来解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.