2016-01-18 30 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