Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FindViewById() not finding View

Just added a new button to my already-working-fine layout, but the findViewById function seems to be angry with something I don't get to understand.

Here's a bit of the layout:

<LinearLayout
        ...
    >
    <ListView
        android:id="@+id/my_lovely_list"
        android:layout_width="fill_parent"
        android:layout_weight="1" 
        />

    <Button
        android:id="@+id/my_lovely_butt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/exit_b"
        android:layout_weight="0"
        android:clickable="true"
        />

</LinearLayout>

And here's a bit of the coding:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ...
    list_o = (ListView)findViewById(R.id.my_lovely_list);
    butt_o = (Button)findViewById(R.id.my_lovely_butt);
    ...
}

So, the big mistery is that the ListView is found without any problem, but the Button won't by any means. I've already tried cleaning the Proyect, and look throught the posts I've found here... but still don't get to find the problem! Any thoughts?

like image 900
DrKiss Avatar asked Jul 13 '12 09:07

DrKiss


1 Answers

import yourpackagename.R;

instead of android.R;

import R of your package

Also Clean your project that will refresh your entire project then you will also find ID of button also

like image 136
MAC Avatar answered Oct 12 '22 22:10

MAC