根据Playstore ANR&崩溃应用程序在SplashScreen oncreate上抛出空指针。我检查了它的功能,看起来很好。并非所有手机都会崩溃。
我的SplashActivity.java
package com.example.app;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
public class SplashActivity extends AppCompatActivity {
String path = "";
String banner = "";
String title = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
if(getIntent().getExtras() != null){
Log.e("splash", "from push link");
path = getIntent().getExtras().getString("link");
banner = getIntent().getExtras().getString("bannerImage");
title = getIntent().getExtras().getString("title");
String link = String.valueOf(Html.fromHtml(Html.fromHtml(path).toString()));
String imgurl = String.valueOf(Html.fromHtml(Html.fromHtml(banner).toString()));
Log.e("link----", "link--" + link);
SharedPreferences pref = getApplicationContext().getSharedPreferences("Push", MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
String pushtitle = pref.getString("pushtitle", "");
StringBuilder sb = new StringBuilder();
sb.append(pushtitle).append(title).append(",");
Log.e("pushtitle===========", sb.toString());
editor.putString("pushtitle", sb.toString());
String links = pref.getString("link", "");
StringBuilder sb2 = new StringBuilder();
sb2.append(links).append(link).append(",");
Log.e("link===========", sb2.toString());
editor.putString("link", sb2.toString());
String imgurlstr = pref.getString("imgurl", "");
StringBuilder sb3 = new StringBuilder();
sb3.append(imgurlstr).append(imgurl).append(",");
Log.e("imgurl===========", sb3.toString());
editor.putString("imgurl", sb3.toString());
editor.commit();
}
int secondsDelayed = 1;
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
if (path != "") {
Log.e("splash", "path==" + path);
intent.putExtra("link", String.valueOf(Html.fromHtml(Html.fromHtml(path).toString())));
}
startActivity(intent);
finish();
}
}, secondsDelayed * 1000);
}
}
Playstore崩溃报告如下。 java.lang.NullPointerException com.example.app.SplashActivity.onCreate
java.lang.RuntimeException:at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2984)at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)在android.app.ActivityThread.-wrap14 (ActivityThread.java)在android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1642)在android.os.Handler.dispatchMessage上 (Handler.java:102)在android.os.Looper.loop(Looper.java:154)at android.app.ActivityThread.main(ActivityThread.java:6776)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1496)at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1386)引起:java.lang.NullPointerException:
在java.io.StringReader。 (StringReader.java:50)at android.text.HtmlToSpannedConverter.convert(Html.java:758)at android.text.Html.fromHtml(Html.java:245)at android.text.Html.fromHtml(Html.java:188)at com.example.app.SplashActivity.onCreate(SplashActivity.java:27)
在android.app.Activity.performCreate(Activity.java:6955)at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1126)at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2927
编辑:调试应用程序我收到以下错误:
会话开始后,日志消息将会跟进...
I / art(3818):没有迟到-Xcheck:jni(已经开启)W / art
(3818):使用默认值的X86的意外CPU变体:x86 W / System (3818):ClassLoader引用了未知路径: /data/app/com.example.app-1/lib/x86 D / FirebaseApp(3818): com.google.firebase.auth.FirebaseAuth未链接。跳绳 初始化。 W / InstanceID / Rpc(3818):找到10012 D / FirebaseApp( 3818):com.google.firebase.crash.FirebaseCrash未链接。跳绳 初始化。 I / FA(3818):应用程序测量正在启动, 版本:10084 I / FA(3818):启用调试日志记录运行:adb shell setprop log.tag.FA VERBOSE I / FA(3818):启用更快 调试模式事件记录运行:I / FA(3818):adb shell setprop debug.firebase.analytics.app com.example.app I / FirebaseInitProvider( 3818):FirebaseApp初始化成功W / art(3818):之前 Android 4.1,方法android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList,android.graphics.PorterDuff $ Mode) 会错误地覆盖package-private方法 android.graphics.drawable.Drawable E / splash(3818):来自推送链接 D / AndroidRuntime(3818):关闭VM E / AndroidRuntime(3818): 致命异常:主要E / AndroidRuntime(3818):流程: com.example.app,PID:3818 E / AndroidRuntime(3818): java.lang.RuntimeException:无法启动活动 ComponentInfo {} com.example.app/com.example.app.SplashActivity: java.lang.NullPointerException:尝试调用虚方法' int java.lang.String.length()'在null对象引用上 E / AndroidRuntime(3818):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) E / AndroidRuntime(3818):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) E / AndroidRuntime(3818):at android.app.ActivityThread.-wrap12(ActivityThread.java) E / AndroidRuntime(3818):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460) E / AndroidRuntime(3818):at android.os.Handler.dispatchMessage(Handler.java:102)E / AndroidRuntime( 3818):在android.os.Looper.loop(Looper.java:154)E / AndroidRuntime( 3818):在android.app.ActivityThread.main(ActivityThread.java:6077) E / AndroidRuntime(3818):at java.lang.reflect.Method.invoke(Native 方法)E / AndroidRuntime(3818):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865) E / AndroidRuntime(3818):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) E / AndroidRuntime(3818):引起:java.lang.NullPointerException: 尝试调用虚方法' int java.lang.String.length()'在...上 null对象引用E / AndroidRuntime(3818):at java.io.StringReader。(StringReader.java:50)E / AndroidRuntime( 3818):在android.text.HtmlToSpannedConverter.convert(Html.java:758) E / AndroidRuntime(3818):在android.text.Html.fromHtml(Html.java:245) E / AndroidRuntime(3818):在android.text.Html.fromHtml(Html.java:188) E / AndroidRuntime(3818):at com.example.app.SplashActivity.onCreate(SplashActivity.java:27) E / AndroidRuntime(3818):at android.app.Activity.performCreate(Activity.java:6662) E / AndroidRuntime(3818):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) E / AndroidRuntime(3818):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) E / AndroidRuntime(3818):... 9更多
答案 0 :(得分:0)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
if(getIntent().getExtras() != null && this.getIntent().getExtras().containsKey("yourKey")){
try {
Log.e("splash", "from push link");
path = getIntent().getExtras().getString("link");
banner = getIntent().getExtras().getString("bannerImage");
title = getIntent().getExtras().getString("title");
String link = String.valueOf(Html.fromHtml(Html.fromHtml(path).toString()));
String imgurl = String.valueOf(Html.fromHtml(Html.fromHtml(banner).toString()));
Log.e("link----", "link--" + link);
SharedPreferences pref = getApplicationContext().getSharedPreferences("Push", MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
String pushtitle = pref.getString("pushtitle", "");
StringBuilder sb = new StringBuilder();
sb.append(pushtitle).append(title).append(",");
Log.e("pushtitle===========", sb.toString());
editor.putString("pushtitle", sb.toString());
String links = pref.getString("link", "");
StringBuilder sb2 = new StringBuilder();
sb2.append(links).append(link).append(",");
Log.e("link===========", sb2.toString());
editor.putString("link", sb2.toString());
String imgurlstr = pref.getString("imgurl", "");
StringBuilder sb3 = new StringBuilder();
sb3.append(imgurlstr).append(imgurl).append(",");
Log.e("imgurl===========", sb3.toString());
editor.putString("imgurl", sb3.toString());
editor.commit();
} catch (NullPointerException e ) {
path = "";
banner = "";
title = "";
}
}