2016-05-08 44 views
4

我試圖運行這個庫的樣本: https://github.com/mxn21/FlowingDrawerFlowingDrawer樣品不運行

它正常工作與這種過時的build.gradle:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 22 
    buildToolsVersion "22.0.1" 

    defaultConfig { 
     applicationId "com.mt.stackoverflow" 
     minSdkVersion 9 
     targetSdkVersion 22 
     versionCode 120 
     versionName "1.2.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:22.2.0' 
    compile 'com.android.support:recyclerview-v7:22.+' 
    compile 'com.android.support:design:22.2.1' 
    compile 'com.squareup.picasso:picasso:2.5.0' 
    compile 'com.android.support:cardview-v7:22.+' 
    compile 'com.nineoldandroids:library:2.4.0' 
    compile 'com.mxn.soul:flowingdrawer-core:1.2.2' 
} 

但它失敗,此更新的build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    defaultConfig { 
     applicationId "com.mt.stackoverflow" 
     minSdkVersion 9 
     targetSdkVersion 23 
     versionCode 120 
     versionName "1.2.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:23.3.0' 
    compile 'com.android.support:recyclerview-v7:23.3.0' 
    compile 'com.android.support:design:23.3.0' 
    compile 'com.squareup.picasso:picasso:2.5.0' 
    compile 'com.android.support:cardview-v7:23.3.0' 
    compile 'com.nineoldandroids:library:2.4.0' 
    compile 'com.mxn.soul:flowingdrawer-core:1.2.2' 
} 

致命異常:主要 過程:com.mt.stackoverflow,PID:31453 java.lang.RuntimeException:無法啓動活動 ComponentInfo {com.mt.stackoverflow/com.mt.stackoverflow.MainActivity}: java.lang.IllegalArgumentException:Target must not爲空。 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 在android.app.ActivityThread.-wrap11(ActivityThread.java) 在Android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148)處的android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344) ( ) at android.app.ActivityThread.main(ActivityThread.java:5422) at java.lang.reflect.Method.invoke(Native Method) 在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 造成的:java.lang中.IllegalArgumentException:目標不得爲 null。 在com.squareup.picasso.RequestCreator.into(RequestCreator.java:607) 在com.squareup.picasso.RequestCreator.into(RequestCreator.java:590) 在 com.mt.stackoverflow.MyMenuFragment.setupHeader(MyMenuFragment的.java:44) 在 com.mt.stackoverflow.MyMenuFragment.onCreateView(MyMenuFragment.java:31) 在 android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) 在 機器人。 support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) at android.support.v4.app.FragmentMa nagerImpl.moveToState(FragmentManager.java:1252) 在 android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) 在 android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java: 1617) 在 android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) 在 android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602) 在 android.app .Instrumentation.callActivityOnStart(Instrumentation.java:1237) at android.app.Activity.performStart(Activity.java:6268) at android.app.ActivityThread.performLaunchActivity(ActivityThread。Java的:2379) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 在android.app.ActivityThread.-wrap11(ActivityThread.java) 在 android.app.ActivityThread $ H.handleMessage(ActivityThread .java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java :5422) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCa ller.run(ZygoteInit.java:726) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我怎麼可以運行與moste最近構建的樣本的任何想法。 gradle依賴關係?

+0

show MyMenuFragment.java: – Elltz

回答

1

該項目試圖訪問的標頭中的ImageView,fragment_menu.xml,其方式與新版本的支持庫不兼容。你可以在this post找到詳細信息。

ImageView是在Picasso通話用作target並且由於ImageView不再可以發現它是空那就是IllegalArgumentException: Target must not be null錯誤的原因。

要修復它打開類MyMenuFragment並替換爲以下onCreateView(...)

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_menu, container, false); 

    View header = ((NavigationView) view.findViewById(R.id.vNavigation)).getHeaderView(0); 
    ivMenuUserProfilePhoto = (ImageView) header.findViewById(R.id.ivMenuUserProfilePhoto); 

    setupHeader(); 
    return setupReveal(view) ; 
} 

基本上可以不再view找到ivMenuUserProfilePhoto直接。您首先需要從NavigationView獲得標題視圖,然後使用標題找到ImageView