简体   繁体   English

使用 getFont 时出现 android.content.res.Resources$NotFoundException

[英]android.content.res.Resources$NotFoundException when using getFont

I developed an android application that is based on Firebase.我开发了一个基于 Firebase 的 android 应用程序。

One of the buttons In the application is used to delete the account.应用程序中的按钮之一用于删除帐户。

Once the account is deleted, I return the user to the main activity by using this:删除帐户后,我使用以下命令将用户返回到主要活动:

AuthUI.getInstance()
        .signOut( context )
        .addOnCompleteListener( task -> {
            Intent intent = new Intent( context, MainActivity.class );
            intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP |
                    Intent.FLAG_ACTIVITY_CLEAR_TASK |
                    Intent.FLAG_ACTIVITY_NEW_TASK );
            context.startActivity( intent );
        } );

Then, when the main activity is created, there are few methods in it.然后,当创建主活动时,其中的方法很少。 One of the methods called activateGPS is used when users first open the app to tell them that they should turn on the GPS.当用户第一次打开应用程序告诉他们应该打开 GPS 时,会使用一种称为activateGPS的方法。

private void activateGPS() {
    new GpsUtils( this ).turnGPSOn( isGPSEnable -> isGPS = isGPSEnable );

    if (!isGPS) {
        PopUps popUps = new PopUps();
        popUps.popSnack( getApplicationContext(), getWindow().getDecorView().findViewById( android.R.id.content ), getString( R.string.Location_Service ) );
    }
}

What causes this problem?是什么导致了这个问题?

When I run it on the emulator everything seems to work fine.当我在模拟器上运行它时,一切似乎都正常。

Thank you If the GPS turned off, a snackbar is shown.谢谢 如果 GPS 关闭,则会显示一个小吃店。

Problem is, that I see in my logs is that when users deleted their accounts, the following error happened:问题是,我在日志中看到的是,当用户删除他们的帐户时,发生了以下错误:

Caused by android.content.res.Resources$NotFoundException
Font resource ID #0x7f090000 could not be retrieved.

androidx.core.content.res.ResourcesCompat.loadFont (ResourcesCompat.java:4)
androidx.core.content.res.ResourcesCompat.getFont (ResourcesCompat.java:19)
com.xx.yy.PopUps.popSnack (PopUps.java:4)
com.xx.yy.MainActivity.activateGPS (MainActivity.java:8)

PopUps.popSnack is built as follows and I use it from an interface: PopUps.popSnack构建如下,我从一个界面使用它:

public void popSnack(Context context, View view, String message) {
    Snackbar snackbar = Snackbar.make( view.findViewById( android.R.id.content ), message, Snackbar.LENGTH_SHORT );
    View sbView = snackbar.getView();
    sbView.setBackgroundColor( context.getResources().getColor( R.color.colorPrimaryDark ) );
    sbView.setElevation( 0f );

    TextView tv = (snackbar.getView()).findViewById( com.google.android.material.R.id.snackbar_text );
    Typeface font = ResourcesCompat.getFont( context, R.font.assistant );
    tv.setTypeface( font );
    tv.setTextSize( 12 );

    if (view.findViewById( R.id.et_Message ) != null) {
        snackbar.setAnchorView( R.id.et_Message );
    } else if (view.findViewById( R.id.bottom_navigation ) != null) {
        snackbar.setAnchorView( R.id.bottom_navigation );
    }
    snackbar.setDuration( 5000 );
    snackbar.show();
}

According to the error you have mentioned, I think the resource you are trying to access isn't available.根据您提到的错误,我认为您尝试访问的资源不可用。 Please make sure that the file is in the font folder.请确保该文件位于字体文件夹中。

   ResourcesCompat.getFont(context,R.font.assistant);

The above code should work fine.上面的代码应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.content.res.Resources$NotFoundException:Android - android.content.res.Resources$NotFoundException : Android android.content.res.Resources$NotFoundException - android.content.res.Resources$NotFoundException 设置ListView时,android.content.res.Resources $ NotFoundException - android.content.res.Resources$NotFoundException when setting a ListView 奥利奥:android.content.res.Resources $ NotFoundException - Oreo: android.content.res.Resources$NotFoundException android.content.res.Resources$NotFoundException: 在 setImageResource 中 - android.content.res.Resources$NotFoundException: in setImageResource android.content.res.Resources $ NotFoundException - android.content.res.Resources$NotFoundException android.content.res.Resources$NotFoundException · 字符串资源 ID # - android.content.res.Resources$NotFoundException · String resource ID # 无法修复android.content.res.Resources $ NotFoundException - Can't fix android.content.res.Resources$NotFoundException Android 12 - 致命异常:android.content.res.Resources$NotFoundException - Android 12 - Fatal Exception: android.content.res.Resources$NotFoundException setTextAppearance导致android.content.res.Resources $ NotFoundException - setTextAppearance causes android.content.res.Resources$NotFoundException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM