2015-02-23 56 views
1

我是Android Studio中的新手,所以这很可能是错误的,但我不明白。我把.jar文件在/ libs文件夹内,增加一条,作为图书馆,现在我的build.gradle文件具有这些依赖关系:Android - 安卓工作室中的毕加索无法加载

compile fileTree(dir: 'libs', include: ['*.jar']) 
compile 'com.android.support:appcompat-v7:21.0.3' 
compile project(':SmoothProgressBar') 
compile 'com.squareup.picasso:picasso:2.5.0' 

我的清单是这样

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.prova" > 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <uses-permission android:name="android.permission.INTERNET" /> 
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

但是当我需要要加载一张图片,它不会做任何事情,logcat也不会有错误。这里是我的代码:

public class MainActivity extends ActionBarActivity { 

private ImageView img; 

private String image = "http://i.stack.imgur.com/LOb1t.png"; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    img = (ImageView) findViewById(R.id.image); 

    Picasso.with(this).setLoggingEnabled(true); 
    Picasso.with(this).load(Uri.parse(image)).into(img); 
    } 

} 

我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/img" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerInParent="true" /> 

</RelativeLayout> 

在Eclipse中没有任何问题的罚款。 在此先感谢。

编辑: 这是我的build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 21 
    buildToolsVersion "21.1.2" 

    defaultConfig { 
     applicationId "com.example.enrico.prova" 
     minSdkVersion 15 
     targetSdkVersion 21 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:21.0.3' 
    compile 'com.squareup.picasso:picasso:2.5.0' 
} 

EDIT2: logcat的:

02-23 16:41:36.857 28865-28865/com.example.enrico.prova D/Picasso﹕ Main  created  [R1] Request{http://www.online-image-editor.com//styles/2014/images/example_image.png} 
02-23 16:41:36.858 28865-28884/com.example.enrico.prova D/Picasso﹕ Dispatcher enqueued  [R1]+0ms 
02-23 16:41:36.876 28865-29238/com.example.enrico.prova D/Picasso﹕ Hunter  executing [R1]+16ms 
02-23 16:41:36.883 28865-28884/com.example.enrico.prova D/Picasso﹕ Dispatcher batched  [R1]+25ms for error 
02-23 16:41:37.112 28865-28884/com.example.enrico.prova D/Picasso﹕ Dispatcher delivered [R1]+254ms 
02-23 16:41:37.112 28865-28865/com.example.enrico.prova D/Picasso﹕ Main  errored  [R1]+255ms 
+0

检查此https://teamtreehouse.com/forum/adding-picasso-in-android-studio – 2015-02-23 11:30:10

+0

试过了,没有工作 – DLock 2015-02-23 11:32:40

+0

有没有日志? – mes 2015-02-23 11:35:06

回答

3

您有权限在<application>之内。他们应该进入<application>以外的<manifest>

+1

哦,上帝,你是对的... 愚蠢的错误... – DLock 2015-02-23 16:35:32

1

你好,请尝试,因为你有一个URI传递给毕加索负载

load(Uri.parse(image)) 

你能不能请更新代码..with Uri.parse ..因为你可以看到它在

enter image description here

+0

做到了,没有工作。 – DLock 2015-02-23 15:29:40

+0

我更新了问题并尝试使用您发布的这张图片。 不起作用 – DLock 2015-02-23 16:15:35

1

你为什么不尝试与Maven中央,而不是像罐子我的一个项目,

compile fileTree(dir: 'libs', include: ['*.jar']) 
compile 'com.android.support:appcompat-v7:21.0.3' 
compile project(':SmoothProgressBar') 
compile 'com.squareup.picasso:picasso:2.5.0' 

,并可以代替getApplicationContext(),你应该只使用this

+0

做到了: private String image =“http://www.online-image-editor.com//styles/2014/images/example_image.png”; Picasso.with(this).load(Uri.parse(image))。成(IMG); 不工作。 我说我gradle这个文件 – DLock 2015-02-23 15:30:29

+0

不应该你的图片路径是“http://www.online-image-editor.com/styles/2014/images/example_image.png” – 2015-02-24 05:56:18