12

as the title suggest, I'm getting that error in at least 3 of the XML layout files, however, I dont see the attritube "showsAsAction" in any of those XML files, did I miss something or am I just blind?, here are the XML files in question:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/findSelected"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Registrar Asistencia" 
        android:onClick="registrarAsistencia"/>

     <ListView 
         android:id="@+id/listaAlumnos" 
         android:layout_width="fill_parent"
         android:layout_height="fill_parent" />

</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center|top"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/lblCuenta"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cuenta"
        android:textAppearance="?android:attr/textAppearanceLarge" />


    <EditText
        android:id="@+id/txtCuenta"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10" /> 

    <TextView
        android:id="@+id/lblPass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Contraseña"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/txtPass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/btnIniciarSesion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="iniciarSesion"
        android:text="Iniciar Sesion" />

</LinearLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Also, I'm using Android 2.2 (API 8) as the target version. I know "showAsAction" was implemented in API 11, but I just cant find the issue here.

Update: The problems panel shows the following errors:

Error generating final archive: java.io.FileNotFoundException: C:\Users\\Documents\Android\Registro de Asistencia\bin\resources.ap_ does not exist

5
  • @BinoyBabu Thanks for answering. Tried but unfortunately didnt work. In fact, I dont know why, but everytime I try to clean the project the R.java file is deleted and does not seems to be autogenerated again. Luckily I have a backup of the project folder. Any ideas on what could it be?
    – Moko
    Dec 3, 2012 at 4:19
  • 2
    Maybe corrupted ADT plugin or Android SDK. Try reinstalling both.
    – Binoy Babu
    Dec 3, 2012 at 4:21
  • Errors in your project. Check the errors panel. Should tell you warnings and errors alike. Reinstalling everything is to traumatic... Check for hidden errors first. Dec 3, 2012 at 4:21
  • Check the Problems panel (Window->Show View ->Problems)
    – znat
    Dec 3, 2012 at 4:24
  • It does have 2 errors, I have updated the OP with them.
    – Moko
    Dec 3, 2012 at 4:28

7 Answers 7

12

I had this problem when I forgot to add appcompat-v7:+ to my project dependencies. You can do it like this in build.gradle:

dependencies {
  compile 'com.android.support:appcompat-v7:+'
}

And this is because I had the following in my menu.xml:

xmlns:app="http://schemas.android.com/apk/res-auto"

and

app:showAsAction="never"

When I removed the xmlns:app namespace and just used android:showAsAction="never", I didn't need the appcompat-v7 library anymore.

4
  • 3
    here it says one must use a custom namespace for showAction developer.android.com/guide/topics/ui/actionbar.html
    – likejudo
    Mar 13, 2014 at 14:13
  • Yeah I guess that would make sense on older devices. Mar 13, 2014 at 16:39
  • I had it opposite way - Studio generated project for Android 2.2, but I later changed my mind and switched to 4.1. But there was this appcompat dependency in the project. It helped to remove it. Jan 3, 2015 at 5:45
  • @LeosLiterak Wow, 2.2? That is an old version of Android. May 12, 2015 at 15:11
8

Are you sure you are looking in the right *.xml file? You seem to look for "showAsAction" in layout xmls, but it's parameter for the menu. Look rather into .../menu/your_activity.xml

The problem you are dealing with is connected with using target less than 4.0 and/or API less than 14.

So,

a) change those parameters,

b) change the value of showAsAction from "never" to "ifRoom".

2
  • Hey, just saw your answer, but I have solved this already, although you were right, I was looking at the wrong XMLs all the time! Thanks for the answer though!
    – Moko
    Dec 16, 2012 at 2:06
  • 2
    I assumed you already got this. I answered for those who could be dealing with the same thing and not have an answer and have a hard time looking for it. Like me. Dec 16, 2012 at 8:41
3

This happens if you have used the resourceidentifier "ShowAsAction" in your XML. This feature is available only from ver11 i guess. If you are trying to run the same on a lower API version this errror is produced. SOLUTION ->> Right click the project > Properties > Android> Build Target > Choose something greater than API 11

2

you must choose an API 14 with version of 4.0 or grater because any version below 4.0 does not contain in its package the showAsAction attribute

1

The right answer is to use

android:showAsAction="ifRoom"

instead where android is

xmlns:android="http://schemas.android.com/apk/res/android"
0
1

ANDROID STUDIO

if you are using ANDROID STUDIO...... use this fix

add

xmlns:compat="http://schemas.android.com/tools"

in menu tag instead of

xmlns:compat="http://schemas.android.com/apk/res-auto "

in menu tag.

-1

If you import your project from Android Studio to eclipse, just add:

<?xml version="1.0" encoding="utf-8"?>

In the head of xml, then it will all fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.