开发者

findViewById(R.id. finding nothing

开发者 https://www.devze.com 2023-03-11 06:39 出处:网络
I\'m using eclipse and it keeps putting out the error message txt cannot be resolved or is not a field

I'm using eclipse and it keeps putting out the error message

txt cannot be resolved or is not a field

And I have this xml

 <EditText
     android:id="@+id/txt"
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
 />

I have this in the java file

    setContentView(R.layout.test);
    txt = (EditText) findViewById(R.id.txt);

and it is locating test fine, but not txt, actually if I 开发者_C百科change test to anything and then add something in that xml file the next line is not registering the id! Is something wrong with eclipse or just my programming?

Any help appriciated


Try cleaning and rebuilding your project; sometimes the builder just gets confused.


As @Ted Hopp suggested, try cleaning you project and rebuild. If it doesn't help, check the Problems view to see what Eclipse doesn't like and hence failed to compile your resources. R.java doesn't get rebuilt even with only one issue with one of your resources. I had encountered this exact problem before, and it took me a while to figure out that's another layout XML I modified that was causing the problem. Once that XML was fixed, R.java started gets updated/rebuilt correctly.


Well Hello all,

i was having a similar issue. I fixed it by saving the XML file!! and then pressing ctrl+space bar and it showed everything Regards Jawad Hussain

0

精彩评论

暂无评论...
验证码 换一张
取 消