2016-01-18 29 views
0

这是我使用的代码,库从jar中导入,图像链接工作正常,我甚至在AndroidManifest.xml中添加了Internet权限。 问题是,当我启动应用程序时,它会打开并关闭而不显示任何内容。毕加索不会显示imgur的图像

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); 
     } 
} 

这是布局

<?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> 

谢谢

+1

使用LogCat检查与您的崩溃相关的Java堆栈跟踪:https://stackoverflow.com/questions/23353173/uncomfort-myapp-has-stopped-how-can-i-solve-this – CommonsWare

+0

您可以发布您的堆栈跟踪以及? :) –

+0

@CommonsWare它真的看起来不像崩溃,这很可能是代码中的错误。感谢您的回答,尽管 –

回答

1

setContentView(R.id.immagine);是错误的。通常你把R.layout.something放入setContentView

+0

谢谢@GeorgiKoemdzhiev。 OP Yussuf Sassi请接受答案,如果它可以帮助你。 – eriuzo

+0

这是@YussufSassi问的问题:p –

0

此外,请记住,除了Layout作为@eriuzo说,这可能是由于Activity

public class MainActivity extends Activity 

对于这些情况,你应该检查logcats如果事情是wrong.but,您可以使用用AppCompatActivity即可解决问题。

+0

这是布局的事情,谢谢^^ –

+0

很明显,though.yw。 – Mohsen