JNI CallVoidMethodV使用挂起异常java.lang.IllegalStateException调用

时间:2015-10-19 08:13:16

标签: java android android-studio

当我启动应用程序时,它会在从服务器加载图像时崩溃。它有时可以正常工作。但一般来说它会崩溃。我怎么解决呢?............................................ ........................

public class HomeFragment extends BaseFragment {

    public static final String TAG = HomeFragment.class.getSimpleName();

    private ViewPager pager;
    private CirclePageIndicator indicator;
    private HomeSliderAdapter sliderAdapter;

    public static HomeFragment newInstance() {
        HomeFragment newInstance = new HomeFragment();
        return newInstance;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View v = inflater.inflate(R.layout.fragment_home, null);
        return v;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        pager = (ViewPager) view.findViewById(R.id.pager);

        TapGestureListener gestureListener = new TapGestureListener(pager, getActivity());
        final GestureDetectorCompat gestureDetector = new GestureDetectorCompat(getActivity(), gestureListener);
        pager.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                gestureDetector.onTouchEvent(event);
                return false;
            }
        });

        Button allBestSellers = (Button) view.findViewById(R.id.allBestSellers);
        Button allFeaturedProducts = (Button) view.findViewById(R.id.allFeaturedProducts);
        Button allNewProducts = (Button) view.findViewById(R.id.allNewProducts);
        RelativeLayout bestSellersTitleLayout = (RelativeLayout) view.findViewById(R.id.bestSellersTitleLayout);
        RelativeLayout featuredTitleLayout = (RelativeLayout) view.findViewById(R.id.featuredTitleLayout);
        RelativeLayout newProductsTitleLayout = (RelativeLayout) view.findViewById(R.id.newProductsTitleLayout);

        TextView bestSellersTitle = (TextView) view.findViewById(R.id.bestSellersTitle);
        TextView featuredTitle = (TextView) view.findViewById(R.id.featuredTitle);
        TextView newProductsTitle = (TextView) view.findViewById(R.id.newProductsTitle);
        bestSellersTitle.setTypeface(App.MUSEO_700);
        featuredTitle.setTypeface(App.MUSEO_700);
        newProductsTitle.setTypeface(App.MUSEO_700);

        allBestSellers.setOnClickListener(getOnClickListener(App.BESTSELLER_ID));
        allFeaturedProducts.setOnClickListener(getOnClickListener(App.FEATURED_ID));
        allNewProducts.setOnClickListener(getOnClickListener(App.NEWS_ID));
        bestSellersTitleLayout.setOnClickListener(getOnClickListener(App.BESTSELLER_ID));
        featuredTitleLayout.setOnClickListener(getOnClickListener(App.FEATURED_ID));
        newProductsTitleLayout.setOnClickListener(getOnClickListener(App.NEWS_ID));

        sliderAdapter = new HomeSliderAdapter(getActivity());
        pager.setAdapter(sliderAdapter);

        indicator = (CirclePageIndicator) view.findViewById(R.id.indicator);
        indicator.setViewPager(pager);

        getSlideShowBanners();

        if (savedInstanceState != null) {
            return;
        }

        String productsTag = HorizontalProductsFragment.TAG;

        HorizontalProductsFragment bestSeller = HorizontalProductsFragment.newInstance(App.BESTSELLER_ID);
        MobisoftUtils.addFragment(getActivity(), R.id.bestSellersContainer, bestSeller, productsTag, false);

        HorizontalProductsFragment featured = HorizontalProductsFragment.newInstance(App.FEATURED_ID);
        MobisoftUtils.addFragment(getActivity(), R.id.featuredProductsContainer, featured, productsTag, false);

        HorizontalProductsFragment newProducts = HorizontalProductsFragment.newInstance(App.NEWS_ID);
        MobisoftUtils.addFragment(getActivity(), R.id.newProductsContainer, newProducts, productsTag, false);

    }

    private OnClickListener getOnClickListener(final String listId) {
        return new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), ProductListActivity.class);
                intent.putExtra(ProductListActivity.LIST_ID, listId);
                intent.putExtra(ProductListActivity.TYPE, LIST_TYPE.LIST.name());
                startActivity(intent);
            }
        };
    }

    private void setSlideShowBanners(ArrayList<SlideModel> list) {
        HomeActivity.slideList = list;
        sliderAdapter.setData(list);

        ViewTreeObserver slideLayoutObserver = pager.getViewTreeObserver();
        slideLayoutObserver.addOnGlobalLayoutListener(layoutListener);

        if (list.size() <= 1) {
            indicator.setVisibility(View.GONE);
        } else {
            indicator.setVisibility(View.VISIBLE);
            MobisoftUtils.setPagerIndicatorWidth(indicator, sliderAdapter.getCount());
        }
    }

    private void getSlideShowBanners() {
        if (HomeActivity.slideList != null) {
             setSlideShowBanners(HomeActivity.slideList);
        } else {
            BaseActivity act = (BaseActivity) getActivity();
            View progress = getView().findViewById(R.id.progressSlide);
            SlideShowCallback callback = new SlideShowCallback(act, this, progress);
            KitapyurduREST.getServiceInterface().getSlideShowBanners(callback);
        }
    }

    private static class SlideShowCallback extends KitapyurduFragmentCallback {

        public SlideShowCallback(BaseActivity activity, HomeFragment fragment, View progress) {
            super(activity, fragment, progress);
        }

        @Override
        public void onSuccess(String message, JsonElement jsonElement) {
            super.onSuccess(message, jsonElement);

            HomeFragment fragment = (HomeFragment) getFragment();

            Gson gson = new Gson();
            Type type = new TypeToken<ArrayList<SlideModel>>() {
            }.getType();
            ArrayList<SlideModel> slideList = gson.fromJson(jsonElement, type);
            fragment.setSlideShowBanners(slideList);
        }

        @Override
        public void onFail(Integer errorCode, String message, JsonElement data) {
            super.onFail(errorCode, message, data);
            HomeFragment fragment = (HomeFragment) getFragment();

            TextView messageSlide = (TextView) fragment.getView().findViewById(R.id.messageSlide);
            messageSlide.setText(R.string.not_found_any_product_on_list);
            messageSlide.setVisibility(View.VISIBLE);

            MobisoftUtils.showSimpleAlert(getActivity(), message);
        }
    }

    private OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

            int viewPagerWidth = pager.getWidth();
            float viewPagerHeight = (float) (viewPagerWidth * (281f / 500f));

            layoutParams.width = viewPagerWidth;
            layoutParams.height = (int) viewPagerHeight;

            pager.setLayoutParams(layoutParams);
            if (Build.VERSION.SDK_INT < 16) {
                pager.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            } else {
                pager.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            }
        }
    };

    class TapGestureListener extends GestureDetector.SimpleOnGestureListener {

        ViewPager pager;
        Context context;

        public TapGestureListener(ViewPager pager, Context context) {
            this.pager = pager;
            this.context = context;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            SlideModel slide = sliderAdapter.getItem(pager.getCurrentItem());
            bannerClicked(slide.getType(), slide.getId());
            return false;
        }
    }

}

错误输出:

   JNI DETECTED ERROR IN APPLICATION: JNI CallVoidMethodV called with pending exception 'java.lang.IllegalStateException' th
        in call to CallVoidMethodV
        from void android.os.MessageQueue.nativePollOnce(long, int)
    "main" prio=5 tid=1 Runnable
      | group="main" sCount=0 dsCount=0 obj=0x763258b0 self=0xb7c85a70
      | sysTid=11197 nice=0 cgrp=apps sched=0/0 handle=0xb6fd0058
      | state=R schedstat=( 0 0 0 ) utm=106 stm=16 core=3 HZ=100
      | stack=0xbe225000-0xbe227000 stackSize=8MB
      | held mutexes= "mutator lock"(shared held)
      native: #00 pc 00004828  /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
      native: #01 pc 00002ec5  /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
      native: #02 pc 0024437d  /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_trait
      native: #03 pc 0022774b  /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_tra
      native: #04 pc 000af2db  /system/lib/libart.so (art::JniAbort(char const*, char const*)+582)
      native: #05 pc 000afa21  /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+60)
      native: #06 pc 000b2b9b  /system/lib/libart.so (art::ScopedCheck::ScopedCheck(_JNIEnv*, int, char const*)+1286)
      native: #07 pc 000ba05f  /system/lib/libart.so (art::CheckJNI::CallVoidMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::_
      native: #08 pc 00060283  /system/lib/libandroid_runtime.so (???)
      native: #09 pc 000746d1  /system/lib/libandroid_runtime.so (android::NativeDisplayEventReceiver::dispatchVsync(long lon
      native: #10 pc 0007494f  /system/lib/libandroid_runtime.so (android::NativeDisplayEventReceiver::handleEvent(int, int, 
      native: #11 pc 00013f07  /system/lib/libutils.so (android::Looper::pollInner(int)+594)
      native: #12 pc 00013fc9  /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+92)
      native: #13 pc 000803fd  /system/lib/libandroid_runtime.so (android::NativeMessageQueue::pollOnce(_JNIEnv*, int)+22)
      native: #14 pc 000b1e37  /data/dalvik-cache/arm/system@framework@boot.oat (Java_android_os_MessageQueue_nativePollOnce_
      at android.os.MessageQueue.nativePollOnce(Native method)
      at android.os.MessageQueue.next(MessageQueue.java:153)
      at android.os.Looper.loop(Looper.java:131)
      at android.app.ActivityThread.main(ActivityThread.java:5696)
      at java.lang.reflect.Method.invoke!(Native method)

    10-19 10:48:50.966 11197-11197/A/art: art/runtime/check_jni.cc:65]   at java.lang.reflect.Method.invoke(Method.java:372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

0 个答案:

没有答案