Skip to content

app中使用application 后lib无法获取context #13

@kipeng

Description

@kipeng
10-26 14:41:16.444: I/System.out(17766): java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getExternalCacheDir()' on a null object reference
10-26 14:41:16.444: I/System.out(17766):    at com.lling.photopicker.utils.OtherUtils.getDiskCacheDir(OtherUtils.java:113)
10-26 14:41:16.444: I/System.out(17766):    at com.lling.photopicker.utils.ImageLoader.initDiskCache(ImageLoader.java:145)
10-26 14:41:16.444: I/System.out(17766):    at com.lling.photopicker.utils.ImageLoader.init(ImageLoader.java:63)
10-26 14:41:16.444: I/System.out(17766):    at com.lling.photopicker.utils.ImageLoader.<init>(ImageLoader.java:58)
10-26 14:41:16.444: I/System.out(17766):    at com.lling.photopicker.utils.ImageLoader.getInstance(ImageLoader.java:110)
10-26 14:41:16.444: I/System.out(17766):    at com.lling.photopicker.adapters.PhotoAdapter.getView(PhotoAdapter.java:198)
10-26 14:41:16.444: I/System.out(17766):    at android.widget.AbsListView.obtainView(AbsListView.java:2346)
10-26 14:41:16.444: I/System.out(17766):    at android.widget.GridView.onMeasure(GridView.java:1065)
10-26 14:41:16.444: I/System.out(17766):    at android.view.View.measure(View.java:18811)

你好,当我app也有一个application时,lib会无法获取context,抛NullPointerException

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

目前经过查找资料使用的方法是:我的application继承你lib中的application解决的
http://stackoverflow.com/questions/7157501/is-it-possible-to-get-applications-context-in-an-android-library-project
请问还有其他的解决方法吗?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions