错误:
12-15 15:21:57.546 11772 11797 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.replaceFirst(java.lang.String, java.lang.String)' on a null object reference 12-15 15:21:57.546 11772 11797 E AndroidRuntime: at com.easemob.analytics.EMActiveCollector$1.run(Unknown Source) 12-15 15:21:57.546 11772 11797 E AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
public static void sendActivePacket(final Context var0) { boolean var1 = PreferenceManager.getDefaultSharedPreferences(var0).getBoolean("actived", false); if(var1) { EMLog.d("init", "s"); } else { try { EMLog.d("init", "d"); (new Thread(new Runnable() { public void run() { StringBuilder var1 = new StringBuilder(); if(p.c().i()) { var1.append("https://"); } else { var1.append("http://"); } String var2 = p.c().l(); if(var2.startsWith("http")) { var1 = new StringBuilder(var2); } else { var1.append(var2); } var1.append("/"); var1.append(EMChatConfig.getInstance().APPKEY.replaceFirst("#", "/")); var1.append("/devices"); String var3 = null; try { String var4 = EMActiveCollector.collectActiveInfo(var0); HashMap var8 = new HashMap(); var3 = HttpClientManager.sendHttpRequest(var1.toString(), var8, var4, HttpClientManager.Method_POST); if(var3.contains("uuid") || var3.contains("duplicate_unique_property_exists")) { Editor var6 = PreferenceManager.getDefaultSharedPreferences(var0).edit(); var6.putBoolean("actived", true); var6.commit(); } } catch (Exception var7) { if(var7.toString().contains("duplicate_unique")) { Editor var5 = PreferenceManager.getDefaultSharedPreferences(var0).edit(); var5.putBoolean("actived", true); var5.commit(); } } } })).start(); } catch (Exception var3) { var3.printStackTrace(); } } }
其中有一句 :
EMChatConfig.getInstance().APPKEY.replaceFirst("#", "/")
注意蓝色部分,环信聊天配置实例的APPKEY为空,所以报错了
解决方法很简单,在AndroidManifest.xml的application节点中加上
<application>
<!-- 设置环信应用的appkey --> <!-- 测试账号,密码 <meta-data android:name="EASEMOB_APPKEY" android:value="-----" /> --> <meta-data android:name="EASEMOB_APPKEY" android:value="-----" /> <!-- 声明sdk所需的service --> <service android:name="com.easemob.chat.EMChatService" android:exported="true" /> <!-- 声明sdk所需的receiver --> <receiver android:name="com.easemob.chat.EMMonitorReceiver" > <intent-filter> <action android:name="android.intent.action.PACKAGE_REMOVED" /> <data android:scheme="package" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> </receiver> <!-- 声明注册时拦截消息对话框信息 receiver --> <!-- <receiver android:name="com.pggmall.origin.receiver.MessageDemo"> <intent-filter android:priority="11"> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> --> <!-- 百度地图所需的service --> <service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote" /> <!-- umeng appkey,可忽略 原来是 ----- 后来申请了替换成自己的 --> <meta-data android:name="UMENG_APPKEY" android:value="-----" > </meta-data> <meta-data android:name="com.baidu.lbsapi.API_KEY" android:value="-----" />
</application>