30

There's two android projects I want to merge, one is Main and the other is linked as Library. But I have some troubles on this line:

Button modificarC;
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_menu_calificaciones);
modificarC = (Button) findViewById(R.id.btn_aseso); //HERE

I tried Project Clean... also I have android-support-v4.jar on my dependencies

And this is my trace:

04-24 19:39:52.568: E/AndroidRuntime(9486): FATAL EXCEPTION: main
04-24 19:39:52.568: E/AndroidRuntime(9486): java.lang.NoSuchFieldError: com.utez.sistemas.sam.R$id.btn_aseso
04-24 19:39:52.568: E/AndroidRuntime(9486):     at com.utez.sistemas.sam.calificaciones.CalificacionesActivity.onCreate(CalificacionesActivity.java:67)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.Activity.performCreate(Activity.java:4465)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.os.Looper.loop(Looper.java:137)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at android.app.ActivityThread.main(ActivityThread.java:4507)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at java.lang.reflect.Method.invokeNative(Native Method)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at java.lang.reflect.Method.invoke(Method.java:511)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
04-24 19:39:52.568: E/AndroidRuntime(9486):     at dalvik.system.NativeStart.main(Native Method)

Also here is the layout:

<LinearLayout
            style="@style/LoginFormContainer"
            android:layout_width="253dp"
            android:layout_height="260dp"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="30dp"
            android:orientation="vertical" >

            <Button
                android:id="@+id/btn_alta"
                android:layout_width="match_parent"
                android:layout_height="63dp"
                android:layout_marginLeft="25dp"
                android:layout_marginTop="5dp"
                android:background="@drawable/btn_altacalif"
                android:contentDescription="@string/action_sign_in_register"
                android:paddingLeft="32dp"
                android:paddingRight="32dp"
                android:textAlignment="center" />

            <Button
                android:id="@+id/btn_aseso"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginLeft="25dp"
                android:layout_marginTop="5dp"
                android:layout_weight="0.16"
                android:background="@drawable/btn_modcalif"
                android:contentDescription="@string/action_sign_in_register"
                android:paddingLeft="32dp"
                android:paddingRight="32dp"
                android:textAlignment="center" />

        </LinearLayout>
Mauricio Zárate
  • 440
  • 1
  • 4
  • 8

4 Answers4

63

I had the same error and it turns out that the resource was overridden.

If you have one project working as a library that declares some id in a given XML file, then your main project redefines that XML, the original id is gone, but you won't see the error until run time.

In my case, a partner deleted and committed the XML from the project, then added it back in the library project. Subclipse didn't seems to notice that because I was up to date, but the XML was there on the main project.

Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
Moxor
  • 1,868
  • 17
  • 13
41

Well, I am Chinese. My English is not good.

I got the question too.

The solution may be: The name of xml file is repeated, eg:a.xml is in your library project, at the same time, a.xml is in your main project. so, please change one of the xml name.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
Bingchean
  • 471
  • 5
  • 6
  • This helped me. I have this issue. Changing the activity XML names did the trick. However I cannot really think the reason for this. – JaydeepW Sep 15 '14 at 06:49
  • This helped and my issue is resolved now. I had duplicate xml files in two lib projects one is framework and second one is common where common uses framework as lib project. Removing the xml from common suited for me and resolved the issue. – Tahir Jilani Jan 28 '15 at 13:47
  • And field was not there in the xml file which was in common lib project. The file from framework was getting replaced by the once in common lib project and since common xml was missing that field it was giving error. silly mistake :P – Tahir Jilani Jan 28 '15 at 13:52
  • Who said Your English is Not Good – Indra Kumar S Aug 20 '17 at 12:48
2

To elaborate on @Moxor's solution, you can either:

  1. Decalare a dummy layout xml, and assign the missing ids to some dummy Views.
  2. Declare the missing ids as resources, the same way you declare a string resource: http://developer.android.com/guide/topics/resources/more-resources.html#Id
Vaiden
  • 15,728
  • 7
  • 61
  • 91
2

Cleaning the project worked for me.