相关疑难解决方法(0)

膨胀类片段时出错

我得到了错误

Unable to start activity ComponentInfo{de.androidbuch.activiti/de.androidbuch.activiti.task.Activity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
Run Code Online (Sandbox Code Playgroud)

当我通过肖像和横向模式切换时.我正在使用片段.我的xml是:

 <LinearLayout android:id="@+id/mainLayout"
               android:orientation="horizontal"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content" >

    <ListView android:id="@+id/android:list"
              android:layout_height="wrap_content"
              android:layout_width="fill_parent"/> 

    <fragment android:id="@+id/fragmentDetails"
              android:layout_height="fill_parent"
              android:layout_width="fill_parent"
              class="de.androidbuch.activiti.task.TaskDetailsFragment"/> 
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

如果我通过横向和纵向模式切换一切正常.但是当我点击我的片段(我可以看到我的片段)然后切换到另一种模式时,我得到了错误.知道怎么解决吗?在这里找到了一些答案,但这些都没有帮助我...

06-21 14:55:05.600: ERROR/AndroidRuntime(7636): FATAL EXCEPTION: main
06-21 14:55:05.600: ERROR/AndroidRuntime(7636): java.lang.RuntimeException: Unable to start activity         
ComponentInfo{de.androidbuch.activiti/de.androidbuch.activiti.task.Activity}:   android.view.InflateException: Binary XML file line #11: Error inflating class fragment
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3097)
06-21 14:55:05.600: ERROR/AndroidRuntime(7636):     at android.app.ActivityThread.access$1600(ActivityThread.java:123)
06-21 …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-fragments

154
推荐指数
13
解决办法
27万
查看次数

应用程序恢复后,Singleton对象变为null

对于我的Android项目,我需要全局单例Cache对象来通过应用程序访问有关用户的数据.

当应用程序进入后台并且在使用其他应用程序一段时间后我尝试在Cache对象中打开应用程序变量时出现问题.当我杀死应用程序并再次打开它时,一切都很好.我正在使用依赖注入来访问Cache对象.如果发生这种情况,为什么app不会再次启动?是否有一些注释可以在低内存条件下保持缓存变量?

这是我的Cache类

class Cache {
    var categories : Array<BaseResponse.Category>? = null
    var user : BaseResponse.User? = null
    var options : BaseResponse.OptionsMap? = null
    var order: MenuOrderDataModel? = null
}
Run Code Online (Sandbox Code Playgroud)

这是DI的存储模块

@Module class StorageModule {

    @Singleton @Provides fun getSharedPrefs(context: Context): SharedPreferences {
        return PreferenceManager.getDefaultSharedPreferences(context)
    }


    @Singleton @Provides fun getCache() : Cache = Cache()
}
Run Code Online (Sandbox Code Playgroud)

我注入对象@Inject lateinit var cache: Cache,然后在启动画面中填充用户数据.

编辑 - 从应用程序和启动活动添加的代码片段

class MyApp : Application() {
    val component: ApplicationComponent by lazy {
        DaggerApplicationComponent
                .builder()
                .appModule(AppModule(this))
                .build()
    } …
Run Code Online (Sandbox Code Playgroud)

android caching dependency-injection kotlin dagger-2

5
推荐指数
1
解决办法
3205
查看次数