bilibili / MagicaSakura

MagicaSakura 是 Android 多主题框架。~ is an Android multi theme library which supporting both daily colorful theme and night theme.
http://app.bilibili.com
Apache License 2.0
3.55k stars 468 forks source link

error inflating TintWidget when running Robolectric unit test #30

Open ladddd opened 7 years ago

ladddd commented 7 years ago

Caused by: java.lang.NullPointerException at org.robolectric.android.XmlResourceParserImpl.getResourceId(XmlResourceParserImpl.java:789) at org.robolectric.android.XmlResourceParserImpl.getAttributeNameResource(XmlResourceParserImpl.java:596) at org.robolectric.shadows.ShadowAssetManager.findAttributeValue(ShadowAssetManager.java:823) at org.robolectric.shadows.ShadowAssetManager.buildTypedValue(ShadowAssetManager.java:747) at org.robolectric.shadows.ShadowAssetManager.attrsToTypedArray(ShadowAssetManager.java:795) at org.robolectric.shadows.ShadowResourcesImpl$ShadowThemeImpl.obtainStyledAttributes(ShadowResourcesImpl.java:177) at android.content.res.ResourcesImpl$ThemeImpl.obtainStyledAttributes(ResourcesImpl.java) at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java:1493) at android.content.Context.obtainStyledAttributes(Context.java:599) at com.bilibili.magicasakura.utils.ColorStateListUtils.inflateColorStateList(ColorStateListUtils.java:110) at com.bilibili.magicasakura.utils.ColorStateListUtils.createFromXmlInner(ColorStateListUtils.java:92) at com.bilibili.magicasakura.utils.ColorStateListUtils.createColorStateList(ColorStateListUtils.java:72) at com.bilibili.magicasakura.utils.TintManager.getColorStateList(TintManager.java:115) at com.bilibili.magicasakura.utils.DrawableUtils.getTintColorList(DrawableUtils.java:173) at com.bilibili.magicasakura.utils.RippleDrawableInflateImpl.inflateDrawable(RippleDrawableInflateImpl.java:41) at com.bilibili.magicasakura.utils.DrawableUtils.createFromXmlInner(DrawableUtils.java:107) at com.bilibili.magicasakura.utils.DrawableUtils.createDrawable(DrawableUtils.java:75) at com.bilibili.magicasakura.utils.TintManager.getDrawable(TintManager.java:146) at com.bilibili.magicasakura.widgets.AppCompatBackgroundHelper.loadFromAttribute(AppCompatBackgroundHelper.java:69) at com.bilibili.magicasakura.widgets.TintButton.<init>(TintButton.java:56) at com.bilibili.magicasakura.widgets.TintButton.<init>(TintButton.java:45) at android.view.LayoutInflater.createView(LayoutInflater.java:645) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727) at android.view.LayoutInflater.rInflate(LayoutInflater.java:858) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.rInflate(LayoutInflater.java:861) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.rInflate(LayoutInflater.java:861) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:994) at android.view.LayoutInflater.rInflate(LayoutInflater.java:854) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.rInflate(LayoutInflater.java:861) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821) at android.view.LayoutInflater.inflate(LayoutInflater.java:518) at android.view.LayoutInflater.inflate(LayoutInflater.java:426) at android.view.LayoutInflater.inflate(LayoutInflater.java:377) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) at com.ladddd.myandroidarch.ui.activity.MainActivity.initView(MainActivity.java:98)

ladddd commented 7 years ago

my test method: `@Test public void clickingPtr_shouldStartPtrActivity() { MainActivity mainActivity = Robolectric.setupActivity(MainActivity.class); mainActivity.findViewById(R.id.btn_ptr).performClick();

    Intent expectedIntent = new Intent(mainActivity, PtrActivity.class);
    assertThat(shadowOf(mainActivity).getNextStartedActivity().filterEquals(expectedIntent)); //how to compare intent equal
}`
xyczero commented 7 years ago

Is it appearing inevitably? Maybe it is causd robolectric.