开发者

cannot be resolved or is not a field findViewById

I cant find whats wrong with my code I am getting cannot be resolved or is not a field on findViewById.

the problems lines are:

       playSeekBar = (ProgressBar) findViewById(R.id.progressBar1);
        buttonPlay = (开发者_开发百科Button) findViewById(R.id.buttonPlay);
         buttonStopPlay = (Button) findViewById(R.id.buttonStopPlay);

my xml code is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar android:id="@+id/progressBar1" android:layout_width="wrap_content"    android:layout_height="wrap_content"></ProgressBar>
<Button android:text="Button" android:id="@+id/buttonPlay" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Button" android:id="@+id/buttonStopPlay" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>

</LinearLayout>

my code is:

 public class radioActivite extends Activity implements OnClickListener {
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.radio_xml);




    initializeUIElements();

    initializeMediaPlayer();
}

private void initializeUIElements() {

       playSeekBar = (ProgressBar) findViewById(R.id.progressBar1);

    playSeekBar.setMax(100);
    playSeekBar.setVisibility(View.INVISIBLE);

    buttonPlay = (Button) findViewById(R.id.buttonPlay);
    buttonPlay.setOnClickListener(this);

    buttonStopPlay = (Button) findViewById(R.id.buttonStopPlay);

tried to clean the code but didn't help me. Thanks for the help!


Try removing your R.java so that it is regenerated. This is often Eclipse that does not see your changes in your res/ directory. Another reason your R.java is not regenerated is you may have a problem in one of your resources (layout, styles, etc.)


Try to remove the keyword android word which will be added before R when you are accesing XML attributes.

import android.R;
...
setContentView(android.R.id.textView);
....
findViewById(android.R.id.Button2);

E.g.

import android.R.id.Button1;

Remove android in the above and place your package directory path..


Check your imports, probably the wrong R file is imported. There should be the

import <your-project-package-name>.R;

line instead of

import android.R;

To quickly organize imports in Eclipse use Ctrl+Shift+O combination. Hope this helps.


  1. remove import android.R;

  2. clean the project

  3. then build the project again


This happens sometimes in eclipse, cleaning the Project has helped me always. It's under Project->clean.


strangely I just tried to debug the app and the errors go away.


remove import android.R;

clean the project.

then build the project again.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜