当我在某些设备上运行应用程序时,所以一切正常,但用户通常使用的其他设备,但随着时间的推移,应用程序退出并在每次打开后写入应用程序不幸停止工作。卸载并再次安装后,只能工作大约10分钟,然后再次出现相同的错误。当我报告错误发挥时,Google向我宣布了此消息。有谁知道该怎么办?抱歉英语不好。
java.lang.NullPointerException
at www.clientbook.cz.ClientBook.controlWebUrl(ClientBook.java:92)
at www.clientbook.cz.ClientBook.access$1(ClientBook.java:90)
at www.clientbook.cz.ClientBook$ClientBookClient.onPageFinished(ClientBook.java:239)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:332)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
这是我的函数controlWebUrl()
private void controlWebUrl(String url) {
//nastavení navigation
if(!url.contains("/index/login") && !url.contains("/index/register") && !url.contains("/index/wait") && !url.contains("/index/active") && !url.contains("/index/forgotpassword")){
mDrawerList.setAdapter(menuListLogin);
login = true;
} else{
mDrawerList.setAdapter(menuList);
login = false;
}
if(url.contains("/index/login")){
setTitle("Přihlášení");
} else if(url.contains("/index/register")){
setTitle("Registrace");
} else if(url.contains("/index/forgotpassword")){
setTitle("Zapomenuté heslo");
} else if(url.contains("/index/wait")){
setTitle("Nepřišel vám e-mail ?");
} else if(url.contains("/index/profile")){
setTitle("Můj profil");
} else if(url.contains("/clients/add")){
setTitle("Přidat klienta");
} else if(url.contains("/clients/list")){
setTitle("Seznam klientů");
} else if(url.contains("/clients/search")){
setTitle("Hledat");
} else if(url.contains("/clients/map")){
setTitle("Mapa klientů");
} else if(url.contains("/clients/show")){
setTitle("Profil klienta");
} else if(url.contains("/clients/edit")){
setTitle("Upravit klienta");
} else if(url.contains("/meetings")){
setTitle("Schůzky");
} else if(url.contains("/forms")){
setTitle("Dotazníky");
} else if(url.contains("/index/account")){
setTitle("Můj účet");
} else if(url.contains("/index/settings")){
setTitle("Nastavení");
} else if(url.contains("/index/search/type/sms")){
setTitle("Hromadná SMS");
} else if(url.contains("/index/search/type/email")){
setTitle("Hromadný E-mail");
} else if(url.contains("/index/search/type/dual")){
setTitle("Hromadná SMS+E-mail");
} else if(url.contains("/index/search/type/history")){
setTitle("Historie Hromadného rozesílání");
} else {
setTitle("ClientBook.cz");
}
}
问题出在哪里?功能必须有回报吗?
这是WebViewClient
private class ClientBookClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
if (!loadingFinished) {
redirect = true;
}
loadingFinished = false;
webview.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView webview, String url, Bitmap favicon){
loadingFinished = false;
}
@Override
public void onPageFinished(WebView webview, String url) {
controlWebUrl(mWebView.getUrl());
if(!redirect){
loadingFinished = true;
}
if(loadingFinished && !redirect && findViewById(R.id.connect).getVisibility() == View.GONE){
findViewById(R.id.load_pb).setVisibility(View.GONE);
findViewById(R.id.load_text).setVisibility(View.GONE);
findViewById(R.id.connect).setVisibility(View.GONE);
mWebView.setVisibility(View.VISIBLE);
} else{
if(findViewById(R.id.connect).getVisibility() == View.VISIBLE){
findViewById(R.id.load_pb).setVisibility(View.GONE);
}
redirect = false;
//error = false;
}
}
public void onReceivedError(WebView view, int errorCod,String description, String failingUrl) {
if(errorCod == -1){
mWebView.goBack();
} else if(errorCod == -2){
mWebView.setVisibility(View.GONE);
TextView error_text = (TextView) findViewById(R.id.load_text);
error_text.setText("Neumím pracovat bez internetu..");
error_text.setVisibility(View.VISIBLE);
findViewById(R.id.connect).setVisibility(View.VISIBLE);
}
}
}
答案 0 :(得分:0)
在手机上,在菜单中启用Developer Options|Don't Save Activities
,这样每次将Activity
置于后台时都会被破坏。然后将您的应用程序放在ClientBook
活动(或其他任何活动)的后台,然后恢复。您可能会遇到该异常,并且可以进行调试。
答案 1 :(得分:0)
听起来问题是变量的生命周期。当你的应用程序处于睡眠状态时,操作系统会进入并释放一些内存。
您可以在onResume()中执行一些空检查以帮助捕获它。基本上你想要检查你的应用程序是否已经被清除了#39;虽然它睡着了。
您可以这样做:
protected void onResume(){
super.onResume();
if(important_val == null){
initialize_app();
return;
}
}
答案 2 :(得分:0)
我在函数controlWebUrl()
中添加了一个条件private void controlWebUrl(String url) {
if(url!=null){
//nastavení navigation
if(!url.contains("/index/login") && !url.contains("/index/register") && !url.contains("/index/wait") && !url.contains("/index/active") && !url.contains("/index/forgotpassword")){
mDrawerList.setAdapter(menuListLogin);
login = true;
} else{
mDrawerList.setAdapter(menuList);
login = false;
}
if(url.contains("/index/login")){
setTitle("Přihlášení");
} else if(url.contains("/index/register")){
setTitle("Registrace");
} else if(url.contains("/index/forgotpassword")){
setTitle("Zapomenuté heslo");
} else if(url.contains("/index/wait")){
setTitle("Nepřišel vám e-mail ?");
} else if(url.contains("/index/profile")){
setTitle("Můj profil");
} else if(url.contains("/clients/add")){
setTitle("Přidat klienta");
} else if(url.contains("/clients/list")){
setTitle("Seznam klientů");
} else if(url.contains("/clients/search")){
setTitle("Hledat");
} else if(url.contains("/clients/map")){
setTitle("Mapa klientů");
} else if(url.contains("/clients/show")){
setTitle("Profil klienta");
} else if(url.contains("/clients/edit")){
setTitle("Upravit klienta");
} else if(url.contains("/meetings")){
setTitle("Schůzky");
} else if(url.contains("/forms")){
setTitle("Dotazníky");
} else if(url.contains("/index/account")){
setTitle("Můj účet");
} else if(url.contains("/index/settings")){
setTitle("Nastavení");
} else if(url.contains("/index/search/type/sms")){
setTitle("Hromadná SMS");
} else if(url.contains("/index/search/type/email")){
setTitle("Hromadný E-mail");
} else if(url.contains("/index/search/type/dual")){
setTitle("Hromadná SMS+E-mail");
} else if(url.contains("/index/search/type/history")){
setTitle("Historie Hromadného rozesílání");
} else {
setTitle("ClientBook.cz");
}
} else{
return;
}
}
然而它似乎正在发挥作用。但我不知道生命周期有什么问题,应用程序睡眠时有什么问题。所以,谢谢你的帮助:)