0

我收到此异常FragmentMainActivity仅在已签名的 apk 中而不是在调试版本中打开。

致命例外:主要

进程:com.curieo.podcast,PID:15376 主题:主题:{} java.lang.NullPointerException:尝试在 com.curieo 的空对象引用上调用虚拟方法“int java.lang.Integer.intValue()”。 podcast.ui.ccf(Unknown Source) at com.curieo.podcast.ui.cca(Unknown Source) at com.curieo.podcast.eaa(Unknown Source) at com.curieo.podcast.eaonPostExecute(Unknown Source) at android。 os.AsyncTask.finish(AsyncTask.java:651) 在 android.os.AsyncTask.-wrap1(AsyncTask.java) 在 android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668) 在 android.os.Handler.dispatchMessage(Handler.java:102) 在 android .os.Looper.loop(Looper.java:148) 在 android.app.ActivityThread.main(ActivityThread.java:5461) 在 java.lang.reflect.Method。在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 的 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 调用(本机方法)

这是引发错误的片段

public class DiscoverFragment extends BaseFragment implements DownloadFeedUrlsFromServerTask.DownloadFeedUrlsFromServerTaskInterface, LoaderManager.LoaderCallbacks<Cursor> {

    ExpandableHeightGridView featuredListView;

    TwoWayGridView popularListView, trendingListView;
    private ServerFeed[] feeds;
    ArrayList<ServerFeed> popularList, featuredList, trendingList;
    AVLoadingIndicatorView progress;

    public DiscoverFragment() {
        // Required empty public constructor
    }

    private BroadcastReceiver podcastAddedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            progress.setVisibility(View.GONE);
            progress.smoothToHide();
            popularListView.setAlpha(1);
            featuredListView.setAlpha(1);
            trendingListView.setAlpha(1);
            popularListView.setClickable(true);
            featuredListView.setClickable(true);
            trendingListView.setClickable(true);
            switch (intent.getAction()) {
                case BroadcastHelper.INTENT_PODCAST_PROCESSED:
                    if (intent.getBooleanExtra(BroadcastHelper.EXTRA_SUCCESS, false)) {
                        Channel channel = Parcels.unwrap(intent.getParcelableExtra(BroadcastHelper.EXTRA_CHANNEL));
                        ChannelProfileActivity.openChannelProfile((BaseActivity) getActivity(),
                                channel, null, false);
                    }
                    break;
            }
        }
    };

    @Override
    protected int getLayoutResourceId() {
        return R.layout.fragment_discover;
    }

    @Override
    protected int getFragmentTitleResourceId() {
        return R.string.title_fragment_discover;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View root = inflater.inflate(R.layout.fragment_discover, container, false);

        initUI(root);
        return root;
    }

    @Override
    public void onResume() {
        super.onResume();
        BroadcastHelper.registerReceiver(getActivity(), podcastAddedReceiver,
                BroadcastHelper.INTENT_PODCAST_PROCESSED, BroadcastHelper.INTENT_OPML_PROCESS_FINISH);
    }

    @Override
    public void onPause() {
        super.onPause();
        BroadcastHelper.unregisterReceiver(getActivity(), podcastAddedReceiver);
    }

    @Override
    public void processRequestResponse(String response) {
        if (response != null && !response.isEmpty()) {
            Gson gson = new Gson();
            this.feeds = gson.fromJson(response, ServerFeed[].class);
            this.populateItems();
        }
    }

    private void populateItems() {

        for (int i = 0; i < this.feeds.length; i++) {
            if (this.feeds[i].getWeight() < 100) {
                Log.e("", "populateItems: " + this.feeds[i].getWeight());
                popularList.add(this.feeds[i]);

            } else if (this.feeds[i].getWeight() > 100 && this.feeds[i].getWeight() < 200) {
                Log.e("", "populateItems " + this.feeds[i].getWeight());

                featuredList.add(this.feeds[i]);

            } else if (this.feeds[i].getWeight() > 200) {
                Log.e("", "populateItems " + this.feeds[i].getWeight());

                trendingList.add(this.feeds[i]);
            }
        }

        CustomFeaturedDiscoverAdapter adapter = new CustomFeaturedDiscoverAdapter(getActivity(), R.layout.featured_discover_list_item, popularList);
        CustomFeaturedDiscoverAdapter adapter1 = new CustomFeaturedDiscoverAdapter(getActivity(), R.layout.featured_discover_list_item, featuredList);
        CustomFeaturedDiscoverAdapter adapter2 = new CustomFeaturedDiscoverAdapter(getActivity(), R.layout.featured_discover_list_item, trendingList);
        featuredListView.setAdapter(adapter1);
        popularListView.setAdapter(adapter);
        trendingListView.setAdapter(adapter2);
        popularListView.setOnItemClickListener((parent, view, position, id) -> {
            podcastOnCLick(popularList, position);

        });

        featuredListView.setOnItemClickListener((adapterView, view, i, l) -> {
            podcastOnCLick(featuredList, i);
        });

        trendingListView.setOnItemClickListener((parent, view, position, id) -> {
            podcastOnCLick(trendingList, position);

        });
    }

    private void podcastOnCLick(ArrayList<ServerFeed> featuredList, int i) {

        PodcastSyncService.addPodcastFromUrl(getActivity(), featuredList.get(i).getFeed_link());
        progress.setVisibility(View.VISIBLE);
        progress.smoothToShow();
        featuredListView.setAlpha((float) 0.40);
        popularListView.setAlpha((float) 0.40);
        trendingListView.setAlpha((float) 0.40);
        Toast.makeText(getActivity(), "Please wait, while the podcast loads.", Toast.LENGTH_LONG).show();
        featuredListView.setClickable(false);
        popularListView.setClickable(false);
        trendingListView.setClickable(false);
    }

    private void initUI(View view) {
        progress = (AVLoadingIndicatorView) view.findViewById(R.id.progress_bar_discover_screen);
        popularListView = (TwoWayGridView) view.findViewById(R.id.listview_discover);
        featuredListView = (ExpandableHeightGridView) view.findViewById(R.id.listview_featured);
        trendingListView = (TwoWayGridView) view.findViewById(R.id.listview_trending);
        popularList = new ArrayList<>();
        featuredList = new ArrayList<>();
        trendingList = new ArrayList<>();

        if (this.feeds == null) {
            DownloadFeedUrlsFromServerTask downloadFeedUrlsFromServerTask = new DownloadFeedUrlsFromServerTask();
            downloadFeedUrlsFromServerTask.downloadFeedUrlsFromServerTaskInterface = this;
            downloadFeedUrlsFromServerTask.execute();
        }
    }

    public static DiscoverFragment newInstance(Bundle args) {
        DiscoverFragment fragment = new DiscoverFragment();

        if (args != null) {
            fragment.setArguments(args);
        }

        return fragment;
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        return null;
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {

    }
}
4

1 回答 1

0

某些服务(如 firebase 登录、推送通知)要求您生成 SHA 证书指纹;这就是此类服务识别您的应用程序的方式,因此您将能够使用他们的服务。Debug 和 Release 变体各自生成不同的指纹。因此,对于该特定Service,您处于 Debug 模式的应用程序与 release 模式是不同的应用程序,因此,如果您的异步任务正在请求数据,并且未经授权,那么它会返回 null,并且您没有处理 null 值,因此崩溃发生。无论哪种方式,您都应该处理空值:if...else,或者至少是 try catch 的事情。干杯,

于 2017-07-06T08:50:11.823 回答