junkchen / BleLib

BleLib是Android低功耗蓝牙4.0及以上开发的辅助库,一行代码解决Ble初始化、扫描、连接、特性读写、设置通知等操作。
Apache License 2.0
245 stars 73 forks source link

下载运行项目必报空指针 #14

Open laksg2009 opened 6 years ago

laksg2009 commented 6 years ago

11-29 14:16:52.141 3123-3123/com.junkchen.blelib.sample E/AndroidRuntime: FATAL EXCEPTION: main Process: com.junkchen.blelib.sample, PID: 3123 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference at com.junkchen.blelib.sample.BleScanActivity$5.convert(BleScanActivity.java:229) at com.junkchen.blelib.sample.BleScanActivity$5.convert(BleScanActivity.java:226) at com.junkchen.blelib.sample.adapter.CommonAdapter.getView(CommonAdapter.java:55) at android.widget.AbsListView.obtainView(AbsListView.java:2464) at android.widget.ListView.measureHeightOfChildren(ListView.java:1286) at android.widget.ListView.onMeasure(ListView.java:1194) at android.view.View.measure(View.java:17782) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5625) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692) at android.widget.LinearLayout.measureVertical(LinearLayout.java:760) at android.widget.LinearLayout.onMeasure(LinearLayout.java:629) at android.view.View.measure(View.java:17782) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5625) at android.widget.FrameLayout.onMeasure(FrameLayout.java:459) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135) at android.view.View.measure(View.java:17782) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5625) at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391) at android.view.View.measure(View.java:17782) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5625) at android.widget.FrameLayout.onMeasure(FrameLayout.java:459) at android.view.View.measure(View.java:17782) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5625) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692) at android.widget.LinearLayout.measureVertical(LinearLayout.java:760) at android.widget.LinearLayout.onMeasure(LinearLayout.java:629) at android.view.View.measure(View.java:17782) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5625) at android.widget.FrameLayout.onMeasure(FrameLayout.java:459) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2644) at android.view.View.measure(View.java:17782) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2398) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1407) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1631) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1285) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6509) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:821) at android.view.Choreographer.doCallbacks(Choreographer.java:624) at android.view.Choreographer.doFrame(Choreographer.java:593) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:807) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5562) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:968) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:763)

RileyGe commented 6 years ago

我也遇到了这个问题,怎么办

junkchen commented 6 years ago

这个应该是你扫描的设备没有名字,我写的demo里对设备名没有做null判断,你可以自己修改下

RileyGe commented 6 years ago

事实是没有扫描到设备,而且非常奇怪的是有时可以有时不可以。具体代码还没有细看,回去测试试。

RileyGe commented 6 years ago

今天是特意来解答这个问题的,junkchen说的很对,我改了一下没有错误了。 具体更改的地方为: 将BleScanActivity和MultipeBleScanActivity两个类的第约228~228行的 holder.setText(R.id.txtv_name, deviceMap.get("name").toString()); 更改为: String tempName =""; if(deviceMap.get("name") != null) tempName = deviceMap.get("name").toString(); holder.setText(R.id.txtv_name, tempName); 更改后至少到现在还没有再出现崩溃的现象。