android常见问题汇总大全

1、Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup Exception details are logged in Window > Show View > Error Log The following classes could not be found: - PreferenceCategory (Fix Build Path, Edit XML) - PreferenceScreen (Fix Build Path, Edit XML)
解决方案: 

I had this problem because I treated the preference list like a normal activity. It's actually completely different. First, you need to move the XML file from res/layout to res/xml (in Eclipse, you have to create this folder manually). You also have to use different Java code:

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class Settings extends PreferenceActivity { //NOT activity!

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Initialize the preference screen defined in /res/xml/preference.xml
        addPreferencesFromResource(R.xml.preferences); //NOT setContentView
    }

}

You'll get a warning for API level >=11 about addPreferencesFromResource being deprecated. That's because Android wants you to switch to a preference screen based on fragments ("PreferenceFragments"), which is a fair bit more complicated. There's an example here.

2、  [exec] ..\res\layout\vw_custom_title.xml:8: error: Error: No resource found that matches the given name (at 'background' with value '@drawable/btn_title_back_big').
     [exec] ..\res\layout\vw_custom_title.xml:22: error: Error: No resource found that matches the given name (at 'background' with value '@drawable/background_title_button_home').
     [exec] ..\res\drawable\add_illegal_button.xml:3: error: Error: No resource found that matches the given name (at 'drawable' with value '@drawable/add_illegal_tapped').
     [exec] ..\res\drawable\add_illegal_button.xml:6: error: Error: No resource found that matches the given name (at 'drawable' with value '@drawable/add_illegal_tapped').

当使用aapt打包资源文件时发现此问题
解决方案
吐槽: 上面的错误提示不一定是正确的,有时候是因为drawable目录地下的其他文件不符合aapt的标准规范,也会导致一些不相关的文件进行报错,真是一个大坑货(要是string.xml里面有错误,也会导致出现上面的错误,真是变态啊)

打开控制台选项,看更详细信息

 因为eclipse的控制台输出量不够,看不到出错的地方的log后再eclipse控制台console 里右键点击出现菜单后选择最后一项 Preferences 里选择调节console buffer size 的大小加个0 
打开后就可以看到以下错误:
[exec] ERROR: 9-patch image D:\workspace\Dili360\res\drawable-hdpi\location_bk.9.png malformed.
     [exec]        No marked region found along edge.
     [exec]        Found along top edge.
     [exec] ERROR: Failure processing PNG image D:\workspace\Dili360\res\drawable-hdpi\location_bk.9.png
就可以通过以下两种方式来解决问题啦
a、是png图片的问题。24位深的。把png图片另存为就好了变成了32位深的
b、 找出问题图片(推荐使用Photoshop将项目中所使用的图片进行一一打开,如Photoshop打开一图片时出错,则该图片肯定有问题),将该图片删除或替换成没问题的图片。再重新ant打包即可。

3、Android Emulator: Installation error: INSTALL_FAILED_VERSION_DOWNGRADE
解决方案一:
It means you're trying to install an app with the same packageName as an app that's already installed on the emulator, but the one you're trying to install has a lower versionCode (integer value for your version number).

You might have installed from a separate copy of the code where the version number was higher than the copy you're working with right now. In either case, uninstall the currently installed copy, or open up Settings > Apps to determine the version number for the installed app, and increment your versionCode to be higher in the AndroidManifest.

解决方案二:

This was happening in my project because I was using an XML resource to set the version code.

AndroidManifest.xml:
android:versionCode="@integer/app_version_code"

app.xml:
<integer name="app_version_code">64integer>

This wasn't a problem in prior versions of adb, however, as of platform-tools r16 this is no longer being resolved to the proper integer. You can either force the re-install using adb -r or avoid the issue entirely by using a literal in the manifest:

4、Android修改package 名比较快速简单的方法
最近开发一组软件 遇到一个问题 一个已经开发好的APK 现在需要在这个基础之上 生成许多个 不同需求的APK发布  所以就不能是相同的package名

  1.     package="com.net.studyplayer.chinese"
  2.     android:versionCode="1"
  3.     android:versionName="1.0" >

复制代码

   比如 我们需要把 package="com.net.studyplayer.chinese" 修改成 "com.net.studyplayer.english"
   这样 我们就可以在同一台机子上安装这两个APK了  因为他们的包名已经不一样了


   但是我们需要修改的地方不只是这一处,还有原文件夹名也要修改

在我们先修改了 AndroidManifest.xml 中的名字之后 会发现文件中凡是有用到R文件的地方都会报错
其实这个就非常简单了
    右键点击上图中  "chinese"的那个包











这样子基本上就所有的报错信息都消失了  clean一遍 然后重新编译  就OK了




开始我操作顺序是反的 还要手动改些东西 但是先改 AndroidManifest.xml   然后在执行后面rename的操作就很快

5、 使用ddms调试android程序时,老是发现 手机管家重复连接一直不断跳动; 同时eclipse的插件经常无故说得不到来自于手机方面的数据
解决方案:
断开手机管家和手机的连接
去掉手机的锁屏,都是锁屏惹的祸

6. eclipse老是无法调试,总是弹出no opened project found for debug session failed
解决方案: 刷新工程,是androidmanifest.xml和本地文件不一致造成的

7.Unable to instantiate activity ComponentInfo{com.tencent.xproject/com.tencent.xproject.activity.gathering.gathering_new.DlgPeopleCntLimit}: java.lang.InstantiationException: can't instantiate class com.tencent.xproject.activity.gathering.gathering_new.DlgPeopleCntLimit; no empty constructor
这个是因为我用startintent来启动一个dialog,肯定出错啦

你可能感兴趣的:(android)