gpt4 book ai didi

java - getColor 方法上的资源未找到异常

转载 作者:行者123 更新时间:2023-12-02 11:53:07 27 4
gpt4 key购买 nike

我正在使用第三方库来使用“幻灯片”( fragment )创建介绍。但是,我收到了 ResourcesNotFoundException,您可以在下面看到。

我不知道异常中提到的这个getColor方法在哪里。它可以从每张幻灯片的 backgroundColor() 属性中抛出吗?

这是我的代码:

public class Tutorial extends MaterialIntroActivity {

private Integer[] tutorialImages = {
R.mipmap.image_main,
R.mipmap.image_long_tap,
R.mipmap.image_menu_slide,
R.mipmap.image_auto_save,
R.mipmap.image_data_security,
R.mipmap.image_donation,
R.mipmap.image_tutorial
};

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

addSlide(new SlideFragmentBuilder()
.title("Main Screen")
.description("Search through the entire Dokkan Cards database and find any card you like.")
.image(tutorialImages[0].intValue())
.backgroundColor(R.color.mainScreen)
.build());


addSlide(new SlideFragmentBuilder()
.title("Tap & Long-Press Actions")
.description("Tap on any card icon to view it's details or Long-press on it to add it to either one of your boxes")
.image(tutorialImages[1].intValue())
.backgroundColor(R.color.long_tap)
.build());

addSlide(new SlideFragmentBuilder()
.title("Side Menu")
.description("Swipe from left to right to access a handful of menu options")
.image(tutorialImages[2].intValue())
.backgroundColor(R.color.side_menu)
.build());

addSlide(new SlideFragmentBuilder()
.title("Auto-Save")
.description("This app saves your box data automatically when you close the app so that you don't have to worry about saving manually")
.image(tutorialImages[3].intValue())
.backgroundColor(R.color.auto_save)
.build());

addSlide(new SlideFragmentBuilder()
.title("Data Security")
.description("Your data is 100% safe since it cannot be accessed by anyone else.All data are stored locally on your device and not on a server or cloud")
.image(tutorialImages[4].intValue())
.backgroundColor(R.color.data_security)
.build());

addSlide(new SlideFragmentBuilder()
.title("Donations")
.description("Although donations are not mandatory, they help a lot in the app's development process. You can submit your donation via the website tab in the app's side menu.")
.image(tutorialImages[5].intValue())
.backgroundColor(R.color.donations)
.build());

addSlide(new TutorialDisclaimerSlide());

addSlide(new SlideFragmentBuilder()
.title("That's it")
.description("That's the end of this tutorial.You can access it at any time from the top right corner of the app")
.image(tutorialImages[6].intValue())
.backgroundColor(R.color.tutorial_end)
.build());
}
}

这是颜色.xml 文件:

<resources>

<!-- MAIN SCREEN PALLET -->
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#FF303F9F</color>
<color name="colorAccent">#FF4081</color>

<!-- USER BOX GLB PALLET -->
<color name="colorPrimaryGLB">#016695</color>
<color name="colorSecondaryGLB">#0378ad</color>

<!-- USER BOX JP PALLET -->
<color name="colorPrimaryJP">#991b1b</color>
<color name="colorSecondaryJP">#9e2d2d</color>

<!-- NAVIGATION MENU PALLET -->
<color name="NavigationDrawerHeader">#6F0AB7</color>
<color name="NavActionBarTextColor">#FFFFFF</color>

<!-- CARD DETAILS PALLET -->
<color name="cardDetailsTextColor">#3F54BF</color>

<!-- ABOUT PAGE [SUB-PAGES] PALLET -->
<color name="Contributors_background">#b01818</color>

<!-- Tutorial PALLET -->
<color name="mainScreen">#283593</color>
<color name="long_tap">#0277BD</color>
<color name="side_menu">#27ae60</color>
<color name="auto_save">#2c3e50</color>
<color name="data_security">#34495e</color>
<color name="donations">#7f8c8d</color>
<color name="tutorial_end">#00838F</color>

<color name="white">#FFFFFF</color>
</resources>

这是我得到的异常:

FATAL EXCEPTION: main
Process: com.dcv.spdesigns.dokkancards, PID: 7958
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
at android.content.res.Resources.getColor(Resources.java:918)
at android.content.Context.getColor(Context.java:508)
at android.support.v4.content.ContextCompat.getColor(ContextCompat.java:409)
at agency.tango.materialintroscreen.MaterialIntroActivity.color(MaterialIntroActivity.java:427)
at agency.tango.materialintroscreen.MaterialIntroActivity.getButtonsColor(MaterialIntroActivity.java:423)
at agency.tango.materialintroscreen.MaterialIntroActivity.access$1300(MaterialIntroActivity.java:44)
at agency.tango.materialintroscreen.MaterialIntroActivity$ColorTransitionScrollListener.setViewsColor(MaterialIntroActivity.java:448)
at agency.tango.materialintroscreen.MaterialIntroActivity$ColorTransitionScrollListener.pageScrolled(MaterialIntroActivity.java:434)
at agency.tango.materialintroscreen.listeners.ViewBehavioursOnPageChangeListener.onPageScrolled(ViewBehavioursOnPageChangeListener.java:54)
at android.support.v4.view.CustomViewPager.dispatchOnPageScrolled(CustomViewPager.java:1922)
at android.support.v4.view.CustomViewPager.onPageScrolled(CustomViewPager.java:1896)
at agency.tango.materialintroscreen.widgets.SwipeableViewPager.onPageScrolled(SwipeableViewPager.java:88)
at android.support.v4.view.CustomViewPager.pageScrolled(CustomViewPager.java:1834)
at android.support.v4.view.CustomViewPager.scrollToItem(CustomViewPager.java:695)
at android.support.v4.view.CustomViewPager.onLayout(CustomViewPager.java:1778)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1166)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:851)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:870)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:724)
at android.view.View.layout(View.java:17523)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2342)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2069)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
12-11 14:00:29.413 7958-7958/com.dcv.spdesigns.dokkancards E/AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:619)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

知道我做错了什么和/或如何跟踪抛出异常的 getColor() 方法吗?

最佳答案

看起来是 known issue与图书馆。

它说:

you need to necessarily override and specify your own values while creating a custom fragment.

 @Override public int buttonsColor() { 
return R.color.custom_slide_buttons;
}

就我个人而言,我会扩展MaterialIntroActivity,然后做这样的事情:

@Override
private int color(@ColorRes int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return getResources().getColor(color, getTheme()));
} else {
return getResources().getColor(color));
}
}

关于java - getColor 方法上的资源未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47752640/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com