FindViewById (int) returns null on one specific button in Android 3.1 in other versions.

This is my first question, but I'm trying to ask correctly.

As the title says with just one button and only in android 3.1 findViewById (int) returns null. Testing on Android 2.2 works, and all other buttons are in both versions of Android. He finds the buttons before this particular line and subsequently.

public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); Button buttonInfo = (Button)findViewById(R.id.buttonInfo);//fine buttonInfo.setOnClickListener(this); ... Button buttonCallOpScreen = (Button)findViewById(R.id.buttonCallOpScreen);//always returns null in android 3.1 ... Button buttonTakePicture = (Button)findViewById(R.id.buttonTakePictureMain);//fine buttonTakePicture.setOnClickListener(this); } 

main.xml :

(I know that I should not use px , but it should only work on my device, so this is normal for this case.)

 <Button android:id="@+id/buttonInfo" android:text="" android:layout_width="332px" android:layout_height="100px" android:background="@drawable/btn_team" /> ... <Button android:id="@+id/buttonCallOpScreen" android:text="" android:layout_width="332px" android:layout_height="100px" android:background="@drawable/btn_operator" /> ... <Button android:id="@+id/buttonTakePictureMain" android:text="" android:layout_width="80px" android:layout_height="80px" android:background="@drawable/btn_take_picture" android:layout_gravity="bottom|left" /> 

Any help would be appreciated, thanks so far.


Answer:

It turned out to be more than ugly. Since several people are working in this project, it seems that this has changed the name in the normal / main.xml layout. Although Android versions prior to 3.1 seem to load layout / main.xml, new ones use layout-normal / main.xml. And since this is more than clear, if the identifier of this button is different from findViewById (int), it should return null.

Sorry to bother you about this and thanks for the comments!

Since I have less than 100 reputations, I cannot answer my question to close it, if anyone could post this answer, I would accept it, thanks.

+6
source share
1 answer

The following answer was discovered by the person who asked the question. Details:

Since several people were working in this project, it seemed to change the name in the layout-normal / main.xml. While Android versions prior to 3.1 seem to load layout / main.xml newer ones use layout-normal / main.xml. And since this is more than understood if the identifier of this button is another findViewById (int), it should return null.

0
source

Source: https://habr.com/ru/post/906473/


All Articles