简体   繁体   中英

FlowingDrawer Sample does not run

I tried to run the sample of this library : https://github.com/mxn21/FlowingDrawer

it works fine with this outdated 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'
}

but it fails with this updated 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'
}

FATAL EXCEPTION: main Process: com.mt.stackoverflow, PID: 31453 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mt.stackoverflow/com.mt.stackoverflow.MainActivity}: java.lang.IllegalArgumentException: Target must not be null. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at 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$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.IllegalArgumentException: Target must not be null. at com.squareup.picasso.RequestCreator.into(RequestCreator.java:607) at com.squareup.picasso.RequestCreator.into(RequestCreator.java:590) at com.mt.stackoverflow.MyMenuFragment.setupHeader(MyMenuFragment.java:44) at com.mt.stackoverflow.MyMenuFragment.onCreateView(MyMenuFragment.java:31) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617) at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:602) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237) at android.app.Activity.performStart(Activity.java:6268 ) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at 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$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Any ideas how I can run the sample with the moste recent build.gradle dependencies ?

The project is trying to access the ImageView in the header of the NavigationView in fragment_menu.xml in a way that is not compatible with the newer version of the support library. You can find the details in this post .

The ImageView is used as the target in a Picasso call and since the ImageView can no longer be found it is null and that is the cause of the IllegalArgumentException: Target must not be null error.

To fix it open the class MyMenuFragment and replace onCreateView(...) with the following:

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

Basically you can no longer find ivMenuUserProfilePhoto directly from view . You first need to get the header view from the NavigationView and then find the ImageView using the header.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM