我是Android的新手。我有一个应用程序,除了android 9(Pie)以外,所有设备都运行良好。
当试图打开这个应用程序时,它崩溃了。
这是我的gradle和代码;
public class TestiFragment extends Fragment {
private static final boolean GRID_LAYOUT = false;
RecyclerView mRecyclerView;
private RssObject rssObject;
private final String RSS_LINK = "http://www.herkul.org/category/kirik-testi/feed/";
private final String RSS_TO_JSON_API = "http://api.rss2json.com/v1/api.json?rss_url=";
private TestiAdapter adapter;
public static TestiFragment newInstance() {
return new TestiFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.testi_layout, container, false);
mRecyclerView = view.findViewById(R.id.testi_recycler);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//setup materialviewpager
if (GRID_LAYOUT) {
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
} else {
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
mRecyclerView.setHasFixedSize(true);
mRecyclerView.addItemDecoration(new MaterialViewPagerHeaderDecorator());
if(Common.isConnectedtoInternet(getActivity())){
//loadRss();
}else{
Toast.makeText(getActivity(), "Lütfen İnternet Bağlantınızı Kontrol Edin!", Toast.LENGTH_SHORT).show();
}
}
private void loadRss() {
AsyncTask loadRssAsync = new AsyncTask() {
ProgressDialog dialog = new ProgressDialog(getActivity());
@Override
protected void onPreExecute() {
dialog.setMessage("Yükleniyor...");
dialog.show();
}
@Override
protected String doInBackground(String... params) {
String result;
HTTPDataHandler http = new HTTPDataHandler();
result = http.getHTTPData(params[0]);
return result;
}
@Override
protected void onPostExecute(String s) {
dialog.dismiss();
rssObject = new Gson().fromJson(s, RssObject.class);
adapter = new TestiAdapter(getActivity(), rssObject);
mRecyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
};
StringBuilder url_Get_Data = new StringBuilder(RSS_TO_JSON_API);
url_Get_Data.append(RSS_LINK);
loadRssAsync.execute(url_Get_Data.toString());
}
public void removeFromFavorites(String name) {
List items = this.rssObject.getItems();
for (int i = 0; i < items.size(); i++){
if (items.get(i).title.equals(name)){
this.adapter.notifyItemChanged(i);
return;
}
}
}
}
这是我的傻瓜;
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.herkultakip.jdevolope.herkultakip"
minSdkVersion 17
targetSdkVersion 28
versionCode 3
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
这是我的logcat;
Process: com.herkultakip.jdevolope.herkultakip, PID: 9265
java.lang.NullPointerException: Attempt to read from field 'java.util.List com.herkultakip.jdevolope.herkultakip.Model.RssObject.items' on a null object reference
at com.herkultakip.jdevolope.herkultakip.Adapter.TestiAdapter.getItemCount(TestiAdapter.java:71)
如果你想要任何东西给你看,请告诉我:)
这个错误有什么问题?
但我不明白为什么它不适用于Android 9而它适用于所有设备?