Android应用程序仅在一些设备上崩溃,其中大部分是华为
我的应用程序在几乎所有的设备上都运行良好,但一些客户回复说,应用程序并没有像那个样崩溃。我从未见过一个真正的设备在同一个应用程序上崩溃。Play store显示了一些崩溃报告,其中包括几乎所有类型的设备型号,但大多数是华为设备Android应用程序仅在一些设备上崩溃,其中大部分是华为,android,retrofit,retrofit2,Android,Retrofit,Retrofit2,我的应用程序在几乎所有的设备上都运行良好,但一些客户回复说,应用程序并没有像那个样崩溃。我从未见过一个真正的设备在同一个应用程序上崩溃。Play store显示了一些崩溃报告,其中包括几乎所有类型的设备型号,但大多数是华为设备 java.lang.NullPointerException: at www.ourshopee.com.fragment.TabDealOfDayFragment$2.onResponse (TabDealOfDayFragment.java:189) at
java.lang.NullPointerException:
at www.ourshopee.com.fragment.TabDealOfDayFragment$2.onResponse (TabDealOfDayFragment.java:189)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run (ExecutorCallAdapterFactory.java:65)
at android.os.Handler.handleCallback (Handler.java:789)
at android.os.Handler.dispatchMessage (Handler.java:98)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6940)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
我在游戏控制台中遇到这个错误,但我在所有的测试设备中工作
implementation 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
implementation 'com.squareup.okhttp3:logging-interceptor:3.0.0-RC1'
implementation 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
implementation 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
请帮帮我,我们将非常感激你的帮助
TabDealFragment
private void getProductsFromServer() {
if (AppUtils.isConnectedToInternet(getContext(), true)) {
llErrorLayout.setVisibility(View.INVISIBLE);
Callback<DealOfDayResponse> callback = new Callback<DealOfDayResponse>() {
@Override
public void onResponse(Response<DealOfDayResponse> response) {
progress_deals.setVisibility(View.INVISIBLE);
if (response.body().getCode()==200) {
if (response.body().getData().getTempSection().size() != 0) {
dealOfDayList.addAll(response.body().getData().getTempSection());
dealproductListingAdapter.notifyDataSetChanged();
}
dealOfDayList.addAll(response.body().getData().getDealOfDay());
dealproductListingAdapter.notifyDataSetChanged();
llErrorLayout.setVisibility(View.INVISIBLE);
tvErrorText.setVisibility(View.INVISIBLE);
loading = true;
}
}
@Override
public void onFailure(Throwable t) {
Log.d("Whats_My_Crash", String.valueOf(t));
progress_deals.setVisibility(View.INVISIBLE);
llErrorLayout.setVisibility(View.VISIBLE);
tvErrorText.setText(getString(R.string.err_unexpected));
}
};
ApiManager.getApi().getService().getDealOfDayProducts(Constants.GET_DEALS_PRODUCTS, AppUtils.getCountryCode(getContext()), page, SUBCATEGORY_ID, BRAND_ID).enqueue(callback);
loading = true;
} else {
llErrorLayout.setVisibility(View.VISIBLE);
tvErrorText.setText(getString(R.string.err_internet));
}
}
private void getProductsFromServer(){
if(AppUtils.isconnectedpointernet(getContext(),true)){
llErrorLayout.setVisibility(View.INVISIBLE);
Callback Callback=new Callback(){
@凌驾
公共响应(响应){
progress_deals.setVisibility(视图.不可见);
if(response.body().getCode()==200){
if(response.body().getData().getTempSection().size()!=0){
addAll(response.body().getData().getTempSection());
dealproductListingAdapter.notifyDataSetChanged();
}
addAll(response.body().getData().getDealOfDay());
dealproductListingAdapter.notifyDataSetChanged();
llErrorLayout.setVisibility(View.INVISIBLE);
tErrorText.setVisibility(视图不可见);
加载=真;
}
}
@凌驾
失效时的公共无效(可丢弃的t){
Log.d(“Whats_My_Crash”,String.valueOf(t));
progress_deals.setVisibility(视图.不可见);
llErrorLayout.setVisibility(View.VISIBLE);
setText(getString(R.string.err_));
}
};
apimager.getApi().getService().getDealOfDayProducts(Constants.GET\u DEALS\u PRODUCTS,AppUtils.getCountryCode(getContext()),页面,子类别\u ID,品牌\u ID)。排队(回调);
加载=真;
}否则{
llErrorLayout.setVisibility(View.VISIBLE);
setText(getString(R.string.err_internet));
}
}
根据您对线路的描述,有两种可能性:
您的后端返回的响应在主体内没有任何临时部分,或者整个主体/数据为空,因此通过改装返回为null
由于body()
已经可以返回null
您应该改进错误处理,检查body是否为null,而不是数据是否返回null,最后检查getTempSection()
是否返回null
原因对我们来说是显而易见的。我们不知道你的后端和你的数据结构或API定义,但是你应该总是考虑处理数据的缺失而不崩溃。代码>
SomeType body = response.body()
if (body.getCode() == 200) {
SomeData data = body.getData()
List<TempSection> tempSections = data.getTempSection()
if (tempSections.size() > 0) {
dealOfDayList.addAll(tempSections);
dealproductListingAdapter.notifyDataSetChanged();
}
List<DealOfDay> dealsOfDay = data.getDealOfDay()
if (dealsOfDay.size() > 0) {
dealOfDayList.addAll(dealsOfDay);
dealproductListingAdapter.notifyDataSetChanged();
}
}
if(body.getCode()==200){
SomeData=body.getData()
List tempSection=data.getTempSection()
如果(tempSections.size()>0){
dealOfDayList.addAll(临时段);
dealproductListingAdapter.notifyDataSetChanged();
}
List dealsOfDay=data.getDealOfDay()
如果(dealsOfDay.size()>0){
dealOfDayList.addAll(dealsOfDay);
dealproductListingAdapter.notifyDataSetChanged();
}
}
你能发布
选项卡DealOfDayFragment
或至少部分内容吗。我的应用程序没有崩溃,所以我无法找到问题所在,…在第189行,你访问了一个对象,它为空。。。不知道哪一行是#189,因为我们在这里看不到行号。在请求从服务器返回之前,当您的应用程序置于后台时,您是否会以某种方式停止请求/回调?或者只告诉我们第189行是什么。在这段代码中,我们看不到行号。Api总是获取大于0的数组大小没有问题。但问题是它几乎在所有设备上都能正常工作,仅在某些设备上出现获取错误Api始终获取数组大小>0没有问题好吧,您遇到的崩溃表明情况并非如此。所以你最好停止说“不是问题”,开始处理这个案例如果(response.body().getCode()=200){if(response.body().getData().getTempSection().size()>0){dealOfDayList.addAll(response.body().getData().getTempSection());dealproductListingAdapter.notifyDataSetChanged();}if(response.body().getData().getDealOfDay().size()>0){dealOfDayList.addAll(response.body().getData().getDealOfDay());dealproductListingAdapter.notifyDataSetChanged()}请不要在注释中删除多行代码。没有人能读到这一点……您已经使用了近2年。请不要只是将一些代码作为答案。解释它的作用以及它如何解决您的问题。也许您需要再次检查该问题