我收到此异常Fragment
,MainActivity
仅在已签名的 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) {
}
}