简体   繁体   English

android.content.res.Resources$NotFoundException:找不到资源 ID #0xffffffff

[英]android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff

I hate posting code, and asking why it doesn't work, but I'm at a loss right now.我讨厌发布代码,并问为什么它不起作用,但我现在不知所措。 I've tried to run the following class below, and I get an exception in logcat which I can't explain.我尝试在下面运行以下 class,但我在 logcat 中遇到了一个我无法解释的异常。 Even a google search yields little results.即使是谷歌搜索也很少产生结果。 Maybe I just don't understand the ecosystem, but the exception has little information.也许我只是不了解生态系统,但异常信息很少。 The exception I'm getting is below:我得到的例外如下:

03-06 21:50:43.031: E/AndroidRuntime(1013): FATAL EXCEPTION: main
03-06 21:50:43.031: E/AndroidRuntime(1013): android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.content.res.Resources.getResourceName(Resources.java:1659)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.support.v4.view.ViewPager.populate(ViewPager.java:1012)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.support.v4.view.ViewPager.populate(ViewPager.java:881)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1366)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.View.measure(View.java:15513)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.View.measure(View.java:15513)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.View.measure(View.java:15513)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.View.measure(View.java:15513)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.Choreographer.doFrame(Choreographer.java:532)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.os.Handler.handleCallback(Handler.java:725)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.os.Looper.loop(Looper.java:137)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at android.app.ActivityThread.main(ActivityThread.java:5039)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at java.lang.reflect.Method.invokeNative(Native Method)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at java.lang.reflect.Method.invoke(Method.java:511)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-06 21:50:43.031: E/AndroidRuntime(1013):     at dalvik.system.NativeStart.main(Native Method)
03-06 21:55:44.231: E/Trace(1033): error opening trace file: No such file or directory (2)

I tried moving the ViewPager to the top level content (ie setContent( pager )) but that didn't seem to work.我尝试将 ViewPager 移动到顶级内容(即 setContent(pager)),但这似乎不起作用。 Any input is welcomed.欢迎任何意见。 The code is below:代码如下:

EDIT* I Simplified the example, and I still get the same problem.编辑*我简化了示例,但我仍然遇到同样的问题。

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AskQuestionActivity extends FragmentActivity
{
    private static LayoutParams MATCH_PARENT = new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT );

    @Override
    protected void onCreate( Bundle savedInstanceState )
    {
        super.onCreate( savedInstanceState );

        ViewPager pager = new ViewPager( this );
        pager.setAdapter( new FragmentPagerAdapter( getSupportFragmentManager() )
        {
            @Override
            public int getCount()
            {
                return 1;
            }

            @Override
            public Fragment getItem( int arg0 )
            {
                return new BoardFragment();
            }
        } );

        setContentView( pager );
    }

    public static class BoardFragment extends Fragment
    {
        @Override
        public View onCreateView( LayoutInflater inflater,
                                  ViewGroup container,
                                  Bundle savedInstanceState )
        {
            TextView textView = new TextView( getActivity() );
            textView.setText( "Board" );
            textView.setGravity( Gravity.CENTER );

            LinearLayout layout = new LinearLayout( getActivity() );
            layout.setLayoutParams( MATCH_PARENT );
            layout.addView( textView );

            return layout;
        }
    }
}

Any help is welcomed.欢迎任何帮助。

So I'll post what I think is the solution to my problem.所以我会发布我认为解决我问题的方法。 After adding a single line to my above code giving the ViewPager a "random" ID;在我上面的代码中添加一行后,给ViewPager一个“随机”ID; it managed to fix my problem.它设法解决了我的问题。

At first I was convinced that setting your own ID is bad practice, but apparently there are legitimate ways of doing this.起初我确信设置自己的 ID 是不好的做法,但显然有合法的方法可以做到这一点。 Namely by creating an ids.xml file and letting the Android ecosystem generate an ID for you.即通过创建一个ids.xml文件并让 Android 生态系统为您生成一个 ID。 I recommend checking out these SO posts for more information - here and here .我建议查看这些 SO 帖子以获取更多信息 - 此处此处

Otherwise, I would recommend just creating an XML file for your layout and getting the ViewPager in your Activity (instead of programmatically instantiating it), but ultimately it all depends on what you're trying to accomplish.否则,我建议只为您的布局创建一个 XML 文件并在您的Activity中获取ViewPager (而不是以编程方式实例化它),但最终这一切都取决于您要完成的工作。

ViewPager pager = new ViewPager(this);

需要设置资源id

pager.setId(0x1000);

Now in 2021 this problem hit me in my Xamarin Forms with a AppShell that was working perfectly, but after upgraded to the last version of many Google AndroidX Nuget Packages started to crash with the message error of this post when opened the menu to change to another page.现在在 2021 年,这个问题在我的 Xamarin Forms 中遇到了我,其 AppShell 运行良好,但是在升级到许多 Google AndroidX Nuget Packages 的最后一个版本后,当打开菜单更改为另一个时,开始崩溃并出现此帖子的消息错误页。 The solution in my case: I downgraded to the previous version all the libraries one by one and the culprit seems to be the Xamarin.AndroidX.Legacy.Support.V4 .我的解决方案:我将所有库一个一个降级到以前的版本,罪魁祸首似乎是Xamarin.AndroidX.Legacy.Support.V4 The v1.0.0.6 was the last one that worked without problems for me. v1.0.0.6 是最后一个对我来说没有问题的版本。 I don't know the reason.我不知道原因。

I was having a similar problem with XML layout files that were under the layout folder.我在布局文件夹下的 XML 布局文件中遇到了类似的问题。 The code used to work in eclipse but when the project was moved to Android Studio I kept getting the android.content.res.Resources$NotFoundException.该代码曾经在 Eclipse 中工作,但是当项目转移到 Android Studio 时,我不断收到 android.content.res.Resources$NotFoundException。

To fix the problem I ended up renaming the XML files that were causing the problem and that solved the problem.为了解决这个问题,我最终重命名了导致问题并解决了问题的 XML 文件。 Before that I tried rebuilding the project, making modifications to the XML file but none of that worked.在此之前,我尝试重建项目,对 XML 文件进行修改,但都没有奏效。

Exactly same problem.完全相同的问题。 I programmatically generated a viewpager in a fragment.我以编程方式在片段中生成了一个 viewpager。 when the fragment back to foreground it crashed.当片段回到前台时它崩溃了。

Even though, I already generated a random id for the view pager it still crash.即使,我已经为视图寻呼机生成了一个随机 ID,但它仍然会崩溃。 The only way is assign a fixed Id to it.唯一的方法是为其分配一个固定的 Id。 Weird!诡异的!

I had the same error.我有同样的错误。 Mine was caused by my Adapter class having one extra textView that did not have a matching imageView.我的原因是我的 Adapter 类有一个额外的 textView 没有匹配的 imageView。 I had 7 TextViews and only 6 ImageViews.我有 7 个 TextView,只有 6 个 ImageView。 It took me a couple hours to figure out a simple mistake.我花了几个小时才弄清楚一个简单的错误。

I had the same issue.我遇到过同样的问题。 The problem was the missing layout file.问题是缺少布局文件。 I had put the layout in layout-xlarge folder but not the layout folder.我已将布局放在 layout-xlarge 文件夹中,但没有放在布局文件夹中。 So small screen tablet had that issue.所以小屏幕平板电脑就有这个问题。 This might give some people a clue.这可能会给一些人一个线索。

I get the same exception when I set adapter viewPager.setAdapter(adapter);当我设置适配器viewPager.setAdapter(adapter);时,我得到了同样的异常。 , only in Android KitKat 4.4. ,仅在 Android KitKat 4.4 中。 I try almost all solutions but not working.我尝试了几乎所有的解决方案,但没有奏效。

In my case, soluation was when I move .xml file drawable-nodpi to drawable folder (which was some SVG images), and Build -> Clean Project then error gone.就我而言,解决方案是当我将.xml文件drawable-nodpi移动到可绘制文件夹(这是一些 SVG 图像),然后Build -> Clean Project然后错误消失了。

I was trying to set an Int value to the TextView directly.我试图直接为TextView设置一个Int值。

Resolved by converting the value to String before setting it to the TextView .通过在将其设置为TextView之前将值转换为String来解决。

I know this is an old question, but maybe the solution I found can help anyone with a similar problem...我知道这是一个老问题,但也许我找到的解决方案可以帮助任何有类似问题的人......

The error message I got was the cryptic 'Android.Content.Res.Resources+NotFoundException: 'Unable to find resource ID #0x0' - only 'resource ID' is different from the origional question.我收到的错误消息是神秘的 'Android.Content.Res.Resources+NotFoundException: 'Unable to find resource ID #0x0' - 只有 'resource ID' 与原始问题不同。

After a lot of research, I finally figured out that the crash had to do with a call to PushModalAsync(), although I had no idea why...经过大量研究,我终于发现崩溃与对 PushModalAsync() 的调用有关,尽管我不知道为什么......

The solution that finally solved this issue for me can be found in the styles.xml file.最终为我解决了这个问题的解决方案可以在 styles.xml 文件中找到。 I had assigned a value of #00ffffff to the android:windowBackground.我已经为 android:windowBackground 分配了 #00ffffff 的值。 It turns out that any hex color in <item name="android:windowBackground">#000000</item> will throw this exception.事实证明, <item name="android:windowBackground">#000000</item>中的任何十六进制颜色都会抛出此异常。

The solution is to assign the hex color in the colors.xml file, and then reference this color in styles.xml like <item name="android:windowBackground">@color/window_background</item>解决方法是在colors.xml文件中指定十六进制颜色,然后在styles.xml中引用这个颜色,比如<item name="android:windowBackground">@color/window_background</item>

This is the 'bug' report that got me on the right track... Exception thrown on PushModalAsync() when android:windowBackground set as HEX这是让我走上正轨的“错误”报告...当 android:windowBackground 设置为 HEX 时,PushModalAsync() 上引发异常

I ran into this error recently when I was trying to use the Navigation Component in Android like so:我最近在尝试使用 Android 中的导航组件时遇到了这个错误,如下所示:

<fragment
    android:id="@+id/my_fragment"
    android:label="My Fragment"
    android:name="com.example.www"

    <action
        android:id="@+id/action_switch_app"
        app:destination="@id/switch_app"
        app:enterAnim="@animator/fragment_open_enter" 
        app:popEnterAnim="@animator/fragment_open_enter" 
        app:popExitAnim="@animator/fragment_fade_exit"/>

</fragment>

<activity 
    android:id="@+id/switch_app"
    android:action="android.intent.action.VIEW"
    android:data="https://another_app.com"
/>

The fragment animations do not belong in the action tag where the destination is an activity in another app.片段动画不属于目标是另一个应用程序中的活动的动作标签。

Solution 2022:解决方案 2022:

REMOVE app/build package.删除应用程序/构建package。

When you change id view delete app/build package.当您更改 id 视图时,删除应用程序/构建 package。


OR: Rebuild Project或:重建项目

在此处输入图像描述


暂无
暂无

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

相关问题 android.content.res.Resources $ NotFoundException:资源ID#0xffffffff - android.content.res.Resources$NotFoundException: Resource ID #0xffffffff 如何消除这个错误 (android.content.res.Resources$NotFoundException: String resource ID #0xffffffff) - how to remove this error (android.content.res.Resources$NotFoundException: String resource ID #0xffffffff) 无法整理:android.content.res.Resources$NotFoundException:资源 ID #0xffffffff - CAN not sort out :android.content.res.Resources$NotFoundException: Resource ID #0xffffffff android.content.res.Resources $ NotFoundException:无法找到资源ID - android.content.res.Resources$NotFoundException: Unable to find resource ID android.content.res.Resources $ NotFoundException:资源ID#0xffffffff。 无法使用查询创建搜索视图 - android.content.res.Resources$NotFoundException: Resource ID #0xffffffff. cannot make search view with query 奇怪的 android.content.res.Resources$NotFoundException:无法找到资源 ID #0x7f06008d - Weird android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f06008d android.content.res.Resources$NotFoundException:无法找到资源 ID #0x7d0 - android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7d0 Android:android.content.res.Resources $ NotFoundException:字符串资源ID - Android: android.content.res.Resources$NotFoundException: String resource ID android.content.res.Resources$NotFoundException · 字符串资源 ID # - android.content.res.Resources$NotFoundException · String resource ID # android.content.res.Resources $ NotFoundException:资源ID#0x0 - android.content.res.Resources$NotFoundException: Resource ID #0x0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM