那些年遇到的Bug(1)

一、SHA-1混淆

Found 2 versions of android-support-v4.jar in the dependency list,
 but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
 Versions found are:
Path: D:\workspace\新闻\libs\android-support-v4.jar
Length: 627582
SHA-1: db0f122c99ef9f90dbab3fada6d191f2880cbb8e
Path: D:\workspace\library\libs\android-support-v4.jar
Length: 385685
SHA-1: 48c94ae70fa65718b382098237806a5909bb096e
 Jar mismatch! Fix your dependencies 

解决方案:将项目的libs下的jar和所添加的依赖库中的jar换成同一个版本的即可,直接覆盖v4jar

二、MainActivity找不到

04-28 06:10:15.508: E/AndroidRuntime(849): Caused by: java.lang.ClassNotFoundException: com.example.aaa.MainActivity
04-28 06:10:15.508: E/AndroidRuntime(849): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-28 06:10:15.508: E/AndroidRuntime(849): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-28 06:10:15.508: E/AndroidRuntime(849): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-28 06:10:15.508: E/AndroidRuntime(849): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
04-28 06:10:15.508: E/AndroidRuntime(849): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
04-28 06:10:15.508: E/AndroidRuntime(849): ... 11 more

分析 : ClassNotFoundException MainActivity类没有找到。 在打包的时候,v4的冲突造成的 解决方案,重新编译,换个SDK 的版本,clean也不行

三、fragment中的view视图没有添加

原因:①因为粗心在oncreateView方法中没有返回自己定义的View视图,而是使用的是super.XXXX,so,项目不报错,但是也运行不出效果

②还有一个就是开启了事务了,没有commit提交,所以代码不报错,但是效果也没有出来

解决方案:①记得要返回自己定义的view视图哦

②一定要commit(555555555),否则你会后悔的哦,亲!

四、android的性能优化

04-29 02:53:44.654: E/AndroidRuntime(326): FATAL EXCEPTION: main
04-29 02:53:44.654: E/AndroidRuntime(326): java.lang.StackOverflowError
04-29 02:53:44.654: E/AndroidRuntime(326): at java.lang.String.getChars(String.java:1003)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.text.TextUtils.getChars(TextUtils.java:63)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.text.TextUtils.indexOf(TextUtils.java:102)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.text.StaticLayout.generate(StaticLayout.java:131)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.text.StaticLayout.<init>(StaticLayout.java:97)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.text.StaticLayout.<init>(StaticLayout.java:54)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.text.StaticLayout.<init>(StaticLayout.java:45)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.TextView.makeNewLayout(TextView.java:4912)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.TextView.onMeasure(TextView.java:5174)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.View.measure(View.java:8171)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
04-29 02:53:44.654: E/AndroidRuntime(326): at android.widget.Line

分析:由于new出来的对象太多了,所以崩溃了

方案:(对于复杂的布局,尽量使用相对布局,节省内存空间,越复杂的布局,越要用相对布局)在开发的过程当中,如果能实现一模一样的需求,尽可能的使用相对布局

理由:相对布局比较灵活,用时少,用户体验好。。

在解析XML的时候,可能相对布局打印出来的时候,比线性布局打印出来的时间长,但是那个是假象 核心功能就是减少冗余的层次从而达到优化UI的目的!

五、外部jar:关于异常Dex Loader:Unable to execute dex: Multiple dex files的处理

在此之前向android项目中添加外部jar包的方法是: 1.将jar包复制到libs文件夹下 2.在eclipse中选中加入的jar包,右击add to build path 这样就可以在程序中使用引进的jar包了 今天引进了xutils的一个解析包,之后就出现了异常Dex Loader:Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl; 前面认为是版本不匹配的问题,版本升级之后也是出现错误,之后得到了

解决方法: 1.删除libs下要引入的jar包,并删除android dependence下的相应的jar包 2.右击android项目,build path->configure build path... 3.在libraries下选择add external jars 这样就成功的引入了外界包!

六、adb连接不上去

 [2015-03-18 23:43:43 - DeviceMonitor] Adb connection Error:远程主机强迫关闭了一个现有的连接。 

解决方案:①首先查看电脑进程,是否存在XXXadb.exe的进程,如果存在,则杀死进程,(建议:不要使用酷狗音乐播放器,可能会冲突)

②重新运行项目,连接你的设备,重新加载,

查看方式window-->show view-->other--->ddms,就可以查看你当前的设备

七、使用xutils工具进行网络解析报错

RetryHandler.retryRequest...   retry error,curr request is null

出现原因:因为没有添加网络标示头 例如:http:// www://等,而我在浏览器中不需要输入这些也可以访问,因为浏览器会自动帮我们补全这些网络标示头

解决方案:亲,一定要记得添加网络标示头哦!!!切记切记

八、调试过程中的安装错误(小米)

[2014-04-29 16:26:26 - 新闻] Installation error: INSTALL_CANCELED_BY_USER
[2014-04-29 16:26:26 - 新闻] Please check logcat output for more details.

[2014-04-29 16:26:26 - 新闻] Launch canceled! 

原因: 只会在小米手机上面才报这个错误,原因是因为当程序在启动的时候,手机处于锁屏状态

解决方案:只需要解锁你的手机即可

九、提示ActivityNotFound错误

03-20 08:19:23.593: E/AndroidRuntime(1498): FATAL EXCEPTION: main
03-20 08:19:23.593: E/AndroidRuntime(1498): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.listviewfrashdemo1/com.imooc.listviewfrashdemo1.WebActivity};have you declared this activity in your AndroidManifest.xml?
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1541)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.app.Activity.startActivityForResult(Activity.java:3351)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.app.Activity.startActivityForResult(Activity.java:3312)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.app.Activity.startActivity(Activity.java:3522)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.app.Activity.startActivity(Activity.java:3490)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at com.imooc.listviewfrashdemo1.MainActivity$1.onItemClick(MainActivity.java:41)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.widget.AdapterView.performItemClick(AdapterView.java:298)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.widget.AbsListView$1.run(AbsListView.java:3529)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.os.Handler.handleCallback(Handler.java:615)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.os.Handler.dispatchMessage(Handler.java:92)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.os.Looper.loop(Looper.java:137)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at android.app.ActivityThread.main(ActivityThread.java:4745)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at java.lang.reflect.Method.invokeNative(Native Method)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at java.lang.reflect.Method.invoke(Method.java:511)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-20 08:19:23.593: E/AndroidRuntime(1498):  at dalvik.system.NativeStart.main(Native Method)

原因:因为没有在manifest文件中配置好这个activity

解决方案:在manifest中添加上需要的activity清单即可

今天就到这了,下次再见

原文发布于微信公众号 - 猿份到(sparkcliff)

原文发表时间:2017-11-04

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏向治洪

RecyclerView 实现gallery画廊效果

1、RecyclerView的基本用法 首先主Activity的布局文件: <RelativeLayout xmlns:android="http://sc...

2645
来自专栏Android开发经验

常用的代码片段,不断更新

1182
来自专栏一个会写诗的程序员的博客

第14章 使用Kotlin 进行 Android 开发(2)

我们使用 fastjson 来解析这个数据。在 app 下面的 build.gradle中添加依赖

682
来自专栏猿份到

仿网易栏目添加功能

在qq群里面发现一个小伙伴有需要做类似于网易新闻客户端栏目拖拽添加的这种效果,特意做了类似效果,效果图如下(文章结尾有源码链接): ? ? ? ? 实现了点击...

3418
来自专栏Android Note

RecycleView之GridLayoutManager的ItemDecoration

1666
来自专栏Android开发与分享

【Android】ButterKnife 8.x详解

35210
来自专栏向治洪

android 自定义gallerey并实现预览功能

自从Gallery被谷歌废弃以后,Google推荐使用ViewPager和HorizontalScrollView来实现Gallery的效果。的确Horizon...

2335
来自专栏潇涧技术专栏

Head First Android SwipeRefreshLayout

本文内容和代码参考自Implementing Swipe to Refresh, an Android Material Design UI Pattern,原...

772
来自专栏木头编程 - moTzxx

安卓 —— 图灵机器人+讯飞语音设计实现

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011415782/article/de...

432
来自专栏Android开发指南

4.TableLayout、回调接口

32212

扫描关注云+社区