使用fr.roland.carousel获取空指针异常

时间:2016-02-02 06:10:01

标签: android carousel

我在我的应用中使用了旋转木马。这是该轮播的github链接: https://github.com/ludovicroland/carousel-android

我得到了这个例外:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Matrix.mapPoints(float[])' on a null object reference
   at fr.rolandl.carousel.CarouselSpinner.pointToPosition(CarouselSpinner.java:269)
   at fr.rolandl.carousel.Carousel.onDown(Carousel.java:782)
   at android.view.GestureDetector.onTouchEvent(GestureDetector.java:550)
   at fr.rolandl.carousel.Carousel.onTouchEvent(Carousel.java:965)
   at android.view.View.dispatchTouchEvent(View.java:8808)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2569)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2239)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2581)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2196)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2581)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2196)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2581)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2196)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2581)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2196)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2581)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2196)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2581)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2196)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2581)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2196)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2581)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2196)
   at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2581)
   at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2196)
   at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2607)
   at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1779)
   at android.app.Activity.dispatchTouchEvent(Activity.java:2846)
   at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:59)
   at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:59)
   at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2568)
   at android.view.View.dispatchPointerEvent(View.java:9003)
   at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4209)
   at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4072)
   at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3627)
   at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3680)
   at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3646)
   at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3763)
   at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3654)
   at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3820)
   at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3627)
   at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3680)
   at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3646)
   at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3654)
   at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3627)
   at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5910)
   at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5884)
   at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5855)
   at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6000)
   at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
   at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
   at android.os.MessageQueue.next(MessageQueue.java:143)
   at android.os.Looper.loop(Looper.java:122)
   at android.app.ActivityThread.main(ActivityThread.java:5910)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

我的代码是:

final ArrayList<Book> books = new ArrayList<>();
    Book book1 = new Book(R.drawable.adabiat_selector, getString(R.string.adabiat));
    books.add(book1);
    Book book2 = new Book(R.drawable.arabi_selector, getString(R.string.arabi));
    books.add(book2);
    Book book3 = new Book(R.drawable.english_selector, getString(R.string.english));
    books.add(book3);

    if (!getResources().getBoolean(R.bool.isTablet)) {
        final Carousel carousel = (Carousel) findViewById(R.id.coverflow);
        CarouselAdapter carouselAdapter = new BooksAdapter(this, books);
        carousel.setAdapter(carouselAdapter);
        carousel.setOnItemClickListener(new CarouselBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(CarouselBaseAdapter<?> carouselBaseAdapter, View view, int position, long l) {
                Intent intent = new Intent(getApplicationContext(), TopicActivity.class);
                intent.putExtra(getString(R.string.page_name), books.get(position).getName());
                intent.putExtra(getString(R.string.book_number), 0);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        });
        carouselAdapter.notifyDataSetChanged();

这是我的xml(它的一部分):

 <LinearLayout
            android:id="@+id/layout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.75">

            <carousel.Carousel xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/coverflow"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="0dp"
                android:animationDuration="200"
                android:clickable="true" />

 </LinearLayout>

我不知道如何解决它。如果你有这个旋转木马并遇到这个问题,或者如果你有想法解决它,请帮忙。

感谢。

0 个答案:

没有答案