无法解决此问题

时间:2019-04-22 08:56:48

标签: android

我正在尝试在github中运行气泡选择器代码(android),但仍然会遇到这些异常。尝试了多个建议但仍然遇到了同样的事情,请帮助我解决这些异常。 尝试了以下操作:无效并重新启动,更改属性文件,清理并重建

XML代码:

<com.igalata.bubblepicker.rendering.BubblePicker
    android:id="@+id/picker"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:backgroundColor="@android:color/white" />

Java代码:

public class Screen1Animation extends AppCompatActivity {

BubblePicker picker;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen1animation);
    //picker = (BubblePicker)findViewById(R.id.picker);
    final String[] titles = getResources().getStringArray(R.array.titles);
    final TypedArray colors = getResources().obtainTypedArray(R.array.colors);
    final TypedArray images = getResources().obtainTypedArray(R.array.images);

    try {
        picker.setAdapter(new BubblePickerAdapter() {

            @Override
            public int getTotalCount() {
                return titles.length;
            }

            @NotNull
            @Override
            public PickerItem getItem(int position) {
                PickerItem item = new PickerItem();
               item.setTitle(titles[position]);
                item.setGradient(new BubbleGradient(colors.getColor((position * 2) % 8, 0),
                        colors.getColor((position * 2) % 8 + 1, 0), BubbleGradient.HORIZONTAL));
                //item.setTypeface(mediumTypeface);
                item.setTextColor(ContextCompat.getColor(Screen1Animation.this, android.R.color.white));
                item.setBackgroundImage(ContextCompat.getDrawable(Screen1Animation.this, images.getResourceId(position, 0)));
                return item;
            }
        });

例外:

FATAL EXCEPTION: main
Process: com.example.sampleapp, PID: 24972
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sampleapp/com.example.sampleapp.Screen1Animation}: android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
    at android.app.ActivityThread.-wrap12(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
    at android.os.Handler.dispatchMessage(Handler.java:108)
    at android.os.Looper.loop(Looper.java:166)
    at android.app.ActivityThread.main(ActivityThread.java:7425)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
 Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:288)
    at android.content.res.Resources.getDrawableForDensity(Resources.java:1026)
    at android.content.res.Resources.getDrawable(Resources.java:969)
    at android.content.Context.getDrawable(Context.java:609)
    at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:463)
    at com.example.sampleapp.Screen1Animation$1.getItem(Screen1Animation.java:45)
    at com.igalata.bubblepicker.rendering.BubblePicker.setAdapter(BubblePicker.kt:37)
    at com.example.sampleapp.Screen1Animation.onCreate(Screen1Animation.java:29)
    at android.app.Activity.performCreate(Activity.java:7383)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)

0 个答案:

没有答案