Eclipse reports an error when creating a new android project

This problem occurs because ADT to version 22 or later, the android-support-v7-appcompat.jar library is automatically referenced when a project is created using eclipse , and the default generated Activity will extend to the v7 ActionBarActivity system class. That's why.

Now that you know the reason, the solution to the problem is simple and clear. Let's create a new project to introduce:


Create a minimum version 2.3 compatible with a maximum version 19 for testing.

Once created, you will see the following effect:


An error is reported , so how to solve it? Delete the menu first, this is useless to us, at least I have never used it.

Analysis: 1. Create this project, whether the selected jar needs to be specified, for example, if you want to use actionbar and fragment on version 2.2, you need to import the two libraries v4 and v7 after the project, if necessary. Then import the V7 package, the path is sdk\extras\android\support\v7\appcompat,



After clicking ok, the above v7 error is solved. Now to solve the reason why the R file cannot be generated, most of the cases are the xml file error.

Find the following:


Check the error point under res/values/styles.xml.

 <style name="AppBaseTheme" parent="Theme.AppCompat.Light">

change this to

<style name="AppBaseTheme" parent="android:Theme.Light">

v11 and v14 have the same revision, and can also be deleted directly. After changing it, it will be correct.


Try it out: what is the question?



第二种方法就比价简单了,删掉v7包,


继承Activity,或者自定义BaseActivity,再运行试试。


运行ok。



注意,有时候会报下面这错。

[2016-07-28 09:18:15 - SocketDemo] W/ResourceType( 4360): ResXMLTree_node size 0 is smaller than header size 0x100.
[2016-07-28 09:18:15 - SocketDemo] E:\Androidtools\eclipse\w\SocketDemo\res\menu\main.xml:6: error: No resource identifier found for attribute 'showAsAction' in package 'com.example.socketdemo'


我们找到对应的menu.xml文件

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.socketdemo.MainActivity" >


    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:title="@string/action_settings"
        app:showAsAction="never"/>


</menu>


删掉app:showAsAction="never"

就可以了 。


总结。其实创建项目出来还有很多错误,只要细心,或者百度搜搜,在当今这个社会,还没有解决不了的bug,只有不能解决的工程师,0.0


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324845162&siteId=291194637