人生必须的知识就是引人向光明方面的明灯。这篇文章主要讲述我的应用程序运行良好,除了Android 9版本。我无法理解什么是问题相关的知识,希望能为你提供帮助。
【我的应用程序运行良好,除了Android 9版本。我无法理解什么是问题】我是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 materialviewpagerif (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<
String, String, String>
loadRssAsync = new AsyncTask<
String, String, String>
() {
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 = https://www.songbingjia.com/android/new StringBuilder(RSS_TO_JSON_API);
url_Get_Data.append(RSS_LINK);
loadRssAsync.execute(url_Get_Data.toString());
}public void removeFromFavorites(String name) {
List<
Item>
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而它适用于所有设备?
答案我相信你的错误在你的
loadRss()
函数中。ProgressDialog dialog = new ProgressDialog(getActivity());
自API 26以来,
ProgressDialog
已被弃用.Source你应该使用像ProgressBar
这样的进度指示器代替API>
= 26这解释了为什么它适用于您测试的所有其他Android版本。
推荐阅读
- 10个道德黑客在线培训场
- Android主题定制
- 如何在Android上更改默认的ProgressBar圆圈颜色
- 向AppTheme添加按钮样式不起作用
- 以编程方式更改Chip Widget样式不起作用 - Android
- 在Android上拉伸游戏画面以跨设备统一分辨率
- 如何在android中同步/限制某些异步http调用
- AndroidPlot - 显示垂直域标签
- Android oreo - 推送通知崩溃