这里的Splash Screen代码(它不是我的愿望,而是客户端) - 我唯一做过的事情 - 只是将sone代码替换为加载数据到此活动:
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Constants.API_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
GetAll getAllProducts = retrofit.create(GetAll.class);
Call<ArrayList<Products>> call = getAllProducts.getAll(Constants.PARTNER_ID,
WaterFragment.getMD5Hash(Constants.PARTNER_ID + Constants.API_KEY));
call.enqueue(new Callback<ArrayList<Products>>() {
@Override
public void onResponse(Response<ArrayList<Products>> response, Retrofit retrofit) {
if (response.body() != null) {
ActiveAndroid.beginTransaction();
try {
ProductsDMC product;
for (Products p : response.body()) {
if (new Select().from(ProductsDMC.class).where("product_id = ?", p.id).executeSingle() != null) {
product = new Select().from(ProductsDMC.class).where("product_id = ?", p.id).executeSingle();
product.price = p.price;
} else {
product = new ProductsDMC(p.id, p.article, p.title, p.price, p.amount, p.category_id,
p.brand_id, p.description, p.photo[0], p.option != null ? p.option.bottle_price : "0");
}
product.save();
}
ActiveAndroid.setTransactionSuccessful();
} finally {
ActiveAndroid.endTransaction();
}
}else{
Toast.makeText(SplashActivity.this, "Try later!", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure (Throwable t){
Toast.makeText(SplashActivity.this, "Check your connection!", Toast.LENGTH_SHORT).show();
Log.d("LoloPolo", t.getMessage().toString());
}
});
Intent intent = new Intent(this, ListOrdersActivity.class);
startActivity(intent);
finish();
}
}
今晚我的尸体发送有关应用程序崩溃的信息:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toString()' on a null object reference
at ru.luny.aqualuxe.activity.SplashActivity$3.onFailure(SplashActivity.java:142)
at retrofit.ExecutorCallAdapterFactory$ExecutorCallback$2.run(ExecutorCallAdapterFactory.java:94)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Method.java)
关于这一点:
Toast.makeText(SplashActivity.this, "Try later!", Toast.LENGTH_SHORT).show();
我真的不明白 - Toast.makeText()。show如何导致NPE))
你能帮我吗?
修改
这看起来很奇怪,但是崩溃论者向我显示了错误代码字符串的错误位置。 它不是关于toast而是调试loggin,从异常中获取消息。
答案 0 :(得分:3)
问题是t.getMessage().toString()
您正在onFailure (Throwable t)
部分获得NPE。对于测试用例,添加""+
@Override
public void onFailure (Throwable t){
Toast.makeText(SplashActivity.this, "Check your connection!", Toast.LENGTH_SHORT).show();
Log.d("LoloPolo",""+ t.getMessage().toString());
}
答案 1 :(得分:1)
NPE归于<a4j:ajax>
是非常严重的问题。并不总是Log.d("LoloPolo", t.getMessage().toString());
返回有效对象。打印getMessage()
就足够了。 E.g。
t
(看看here)
这些回调也不会在Log.d("LoloPolo", "Error", t);
上运行。我不会用它们来表示“敬酒。”