血的教训

来源:互联网 发布:红酒专业知识培训软件 编辑:程序博客网 时间:2024/04/28 11:39

罗列调试过程的血的教训,希望以后不要再犯!

1、反射的方法是不能操作UI滴!!!

2、R文件不见了,怎么都不出来??直接去别的项目中拷贝一个过来,稍作改动,control+S就会自动刷新R文件了

不能正确生成R文件一般是资源文件出了错误,如layout命名中有大写字母,drawbale文件以数字开头等等

3、Android studio的R文 件不能生成,除了上述问题之外,还有可能是Modle之间的layout文件重命了,

Android studio的Modle之间类名字是可以重复的,但是layout文件命名不能重复的

4、apk安装失败:

Installation failed with message INSTALL_PARSE_FAILED_MANIFEST_MALFORMED.
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.

WARNING: Uninstalling will remove the application data!

Do you want to uninstall the existing application?


原来是java文件的包名不能以大写字母开头!!


5、最近更新了Androidstudio 之后,出现了Error:java.lang.UnsupportedClassVersionError:com/android/dx/command/Main :Unsupported major.minor version 52.0 异常,

这是因为 compileSdKVersion 和 buildToosVersion 版本对不上导致的,例如我这里compileSdkVersion 是23,而 buildToolsVersion 却是 24.0.0.rc2 。所以,出现Unsupported major.minor version 52.0 异常


只要将 complileSdkVersion 和 builToolsVersion 的版本修改一致就可以了。

例如,我这里将 buildToolsVersion 修改为 23.0.2 就可以了。

虽然理论上说高版本的buildtools是可以兼容低版本的sdk的,但是安全起见,还是尽量尽量保持一致吧。


6、如果你的电脑在多个路径下安装了多个版本的sdk,请自行file--->project structure--->sdk location 、jdklocation确认并适当修改!


7、Error:(22, 0) Gradle DSL method not found: 'compile()'

      possible causes:

      The project '****' may be using a version of Gradle that does not contain the method

问题排查:

第一步:检查gradle的位置及其版本设置是否正确  OK,转下一步

第二步:look at the root gradle.builde
dependencies {    classpath 'com.android.tools.build:gradle:2.1.2'
    compile 'com.google.android.gms:play-services:6.1.11'
(仔细看下面的note ,不要在这里添加你的dependencies 除非确实all的modle都用到了这个依赖,
         最好不要放这里。将上面的compile 移动到具体的modle的配置文件中,如果ok请break;else请转下一步)

    // NOTE: Do not place your application dependencies here; they belong    // in the individual module build.gradle files}


第三步:这是一个只有博主才会犯的低级错误。。。。手抖不小心拖了一下gradle文件,方法名就错了。。。死活也查不出错误。。。。

 

Think of “Gradle DSL method” as a Java method. So in Gradle, methods can be distinguished(区分ed) by either {} or “.”。So

dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])}

is the same as(等同于)//点点和{}的效果是一样的

dependencies.compile fileTree(dir: 'libs', include: ['*.jar'])

where both “dependencies” and “compile” are methods.

So you are including a method somewhere in your build.gradle file that is not supported by your program. For example, make your dependencies this:

dependencies {    nothing 'this.does.nothing.build:gradle:0.7.+'}

Which is the same as writing:

dependencies.nothing 'this.does.nothing.build:gradle:0.7.+'

And you will see an error saying “unsupported Gradle DSL method found: ‘nothing()’!” Obviously "nothing" is not a real method. I just made it up.

So one of your "compile" methods inside your build.gradle is wrong.


8、Android RecycleView  异常 

java.lang.IllegalStateException:Added View has RecyclerView as parent but view is not a real child. Unfiltered index:0


log日志:

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. 07-16 14:54:12.075: E/AndroidRuntime(20475): java.lang.IllegalStateException:  
  2. Added View has RecyclerView as parent but view is not a real child. Unfiltered  
  3. index:0  
  4. 07-16 14:54:12.075: E/AndroidRuntime(20475):     at  
  5. android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:6720)  
  6. 07-16 14:54:12.075: E/AndroidRuntime(20475):     at  
  7. android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:6686)  
  8. 07-16 14:54:12.075: E/AndroidRuntime(20475):     at  
  9. android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:6674)  


在使用RecycleView中 偶尔出现了该异常 

追踪该异常发现出自

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:6720)  


[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. if (child.getParent() == mRecyclerView) { // it was not a scrap but a valid child  
  2.                 // ensure in correct position  
  3.                 int currentIndex = mChildHelper.indexOfChild(child);  
  4.                 if (index == -1) {  
  5.                     index = mChildHelper.getChildCount();  
  6.                 }  
  7.                 if (currentIndex == -1) {  
  8.                     throw new IllegalStateException("Added View has RecyclerView as parent but"  
  9.                             + " view is not a real child. Unfiltered index:"  
  10.                             + mRecyclerView.indexOfChild(child));  
  11.                 }  
  12.                 if (currentIndex != index) {  
  13.                     mRecyclerView.mLayout.moveView(currentIndex, index);  
  14.                 }  
  15.             }  

发现异常原因是  :

recycleView同时进行 "下拉刷新" 和 "加载更多" 而产生冲突   .

recycleView  执行异步的"加载更多"操作后 , 当调用recycleView   的addviewInt方法填充数据时,   发现列表已经被"下拉刷新"删除了. 找不到常规的child.


解决异常:

禁止 RecycleView  "下拉刷新" 和 "加载更多"  同时执行  . 

同一时间只允许用户使用一种动作 (即: 刷新不加载  加载不刷新 )

0 0
原创粉丝点击