Java não reconhece ID de elementos XML do Android

Olá colegas programadores!

Estou fazendo um tutorial, mas acabei por encontrair um problema que não consigo resolview. Quando eu configurei o link de elementos XML paira Java, como este:

  • Android: emulação de cairtão - leia a mensagem ndef com o module nfc PN532
  • Como obter um ID de recurso com um nome de recurso conhecido?
  • Aplicação de exemplo de captura de vídeo do Android
  • Intenção do Android Não é possível resolview o construtor
  • O gerenciador de SDK não encontra java
  • Plugins que não funcionam no Eclipse no Windows 7 de 64 bits
  • Image1 = (ImageView) findViewById(R.id.ivImage1); 

    Não reconhece o id, mesmo que seja o exato no XML. ivImage1 ivImage2 e ivImage3, todos não funcionam, mas o resto dos elementos da class fazem. O que estou fazendo de errado?

    Aqui está o meu código de atividade:

     package com.frostbytedev.addsub; import java.io.IOException; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; public class Photo extends Activity implements OnClickListener { Bitmap bmp; ImageButton ib; Button b; ImageView iv, Image1, Image2, Image3, Image4; Intent i; final static int cameraData = 0; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.photo); initialize(); } private void initialize() { // TODO Auto-generated method stub iv = (ImageView) findViewById(R.id.ivReturnedPic); b = (Button) findViewById(R.id.bSetWall); ib = (ImageButton) findViewById(R.id.ibTakePic); Image1 = (ImageView) findById(R.id.ivImage1); Image2 = (ImageView) findById(R.id.ivImage2); Image3 = (ImageView) findById(R.id.ivImage3); Image4 = (ImageView) findById(R.id.ivImage4); b.setOnClickListener(this); ib.setOnClickListener(this); } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.bSetWall: try { getApplicationContext().setWallpaper(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.ibTakePic: i= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(i, cameraData); break; }//Closes Switch }//Closes OnClick @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ Bundle extras = data.getExtras(); bmp = (Bitmap) extras.get("data"); iv.setImageBitmap(bmp); } }//Closes Class importa android.view.View.OnClickListener; package com.frostbytedev.addsub; import java.io.IOException; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; public class Photo extends Activity implements OnClickListener { Bitmap bmp; ImageButton ib; Button b; ImageView iv, Image1, Image2, Image3, Image4; Intent i; final static int cameraData = 0; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.photo); initialize(); } private void initialize() { // TODO Auto-generated method stub iv = (ImageView) findViewById(R.id.ivReturnedPic); b = (Button) findViewById(R.id.bSetWall); ib = (ImageButton) findViewById(R.id.ibTakePic); Image1 = (ImageView) findById(R.id.ivImage1); Image2 = (ImageView) findById(R.id.ivImage2); Image3 = (ImageView) findById(R.id.ivImage3); Image4 = (ImageView) findById(R.id.ivImage4); b.setOnClickListener(this); ib.setOnClickListener(this); } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.bSetWall: try { getApplicationContext().setWallpaper(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.ibTakePic: i= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(i, cameraData); break; }//Closes Switch }//Closes OnClick @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ Bundle extras = data.getExtras(); bmp = (Bitmap) extras.get("data"); iv.setImageBitmap(bmp); } }//Closes Class importa android.widget.Button; package com.frostbytedev.addsub; import java.io.IOException; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; public class Photo extends Activity implements OnClickListener { Bitmap bmp; ImageButton ib; Button b; ImageView iv, Image1, Image2, Image3, Image4; Intent i; final static int cameraData = 0; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.photo); initialize(); } private void initialize() { // TODO Auto-generated method stub iv = (ImageView) findViewById(R.id.ivReturnedPic); b = (Button) findViewById(R.id.bSetWall); ib = (ImageButton) findViewById(R.id.ibTakePic); Image1 = (ImageView) findById(R.id.ivImage1); Image2 = (ImageView) findById(R.id.ivImage2); Image3 = (ImageView) findById(R.id.ivImage3); Image4 = (ImageView) findById(R.id.ivImage4); b.setOnClickListener(this); ib.setOnClickListener(this); } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.bSetWall: try { getApplicationContext().setWallpaper(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.ibTakePic: i= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(i, cameraData); break; }//Closes Switch }//Closes OnClick @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ Bundle extras = data.getExtras(); bmp = (Bitmap) extras.get("data"); iv.setImageBitmap(bmp); } }//Closes Class } package com.frostbytedev.addsub; import java.io.IOException; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; public class Photo extends Activity implements OnClickListener { Bitmap bmp; ImageButton ib; Button b; ImageView iv, Image1, Image2, Image3, Image4; Intent i; final static int cameraData = 0; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.photo); initialize(); } private void initialize() { // TODO Auto-generated method stub iv = (ImageView) findViewById(R.id.ivReturnedPic); b = (Button) findViewById(R.id.bSetWall); ib = (ImageButton) findViewById(R.id.ibTakePic); Image1 = (ImageView) findById(R.id.ivImage1); Image2 = (ImageView) findById(R.id.ivImage2); Image3 = (ImageView) findById(R.id.ivImage3); Image4 = (ImageView) findById(R.id.ivImage4); b.setOnClickListener(this); ib.setOnClickListener(this); } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.bSetWall: try { getApplicationContext().setWallpaper(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.ibTakePic: i= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(i, cameraData); break; }//Closes Switch }//Closes OnClick @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ Bundle extras = data.getExtras(); bmp = (Bitmap) extras.get("data"); iv.setImageBitmap(bmp); } }//Closes Class } package com.frostbytedev.addsub; import java.io.IOException; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; public class Photo extends Activity implements OnClickListener { Bitmap bmp; ImageButton ib; Button b; ImageView iv, Image1, Image2, Image3, Image4; Intent i; final static int cameraData = 0; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.photo); initialize(); } private void initialize() { // TODO Auto-generated method stub iv = (ImageView) findViewById(R.id.ivReturnedPic); b = (Button) findViewById(R.id.bSetWall); ib = (ImageButton) findViewById(R.id.ibTakePic); Image1 = (ImageView) findById(R.id.ivImage1); Image2 = (ImageView) findById(R.id.ivImage2); Image3 = (ImageView) findById(R.id.ivImage3); Image4 = (ImageView) findById(R.id.ivImage4); b.setOnClickListener(this); ib.setOnClickListener(this); } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.bSetWall: try { getApplicationContext().setWallpaper(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.ibTakePic: i= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(i, cameraData); break; }//Closes Switch }//Closes OnClick @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ Bundle extras = data.getExtras(); bmp = (Bitmap) extras.get("data"); iv.setImageBitmap(bmp); } }//Closes Class } package com.frostbytedev.addsub; import java.io.IOException; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; public class Photo extends Activity implements OnClickListener { Bitmap bmp; ImageButton ib; Button b; ImageView iv, Image1, Image2, Image3, Image4; Intent i; final static int cameraData = 0; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.photo); initialize(); } private void initialize() { // TODO Auto-generated method stub iv = (ImageView) findViewById(R.id.ivReturnedPic); b = (Button) findViewById(R.id.bSetWall); ib = (ImageButton) findViewById(R.id.ibTakePic); Image1 = (ImageView) findById(R.id.ivImage1); Image2 = (ImageView) findById(R.id.ivImage2); Image3 = (ImageView) findById(R.id.ivImage3); Image4 = (ImageView) findById(R.id.ivImage4); b.setOnClickListener(this); ib.setOnClickListener(this); } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.bSetWall: try { getApplicationContext().setWallpaper(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.ibTakePic: i= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(i, cameraData); break; }//Closes Switch }//Closes OnClick @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ Bundle extras = data.getExtras(); bmp = (Bitmap) extras.get("data"); iv.setImageBitmap(bmp); } }//Closes Class } package com.frostbytedev.addsub; import java.io.IOException; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; public class Photo extends Activity implements OnClickListener { Bitmap bmp; ImageButton ib; Button b; ImageView iv, Image1, Image2, Image3, Image4; Intent i; final static int cameraData = 0; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.photo); initialize(); } private void initialize() { // TODO Auto-generated method stub iv = (ImageView) findViewById(R.id.ivReturnedPic); b = (Button) findViewById(R.id.bSetWall); ib = (ImageButton) findViewById(R.id.ibTakePic); Image1 = (ImageView) findById(R.id.ivImage1); Image2 = (ImageView) findById(R.id.ivImage2); Image3 = (ImageView) findById(R.id.ivImage3); Image4 = (ImageView) findById(R.id.ivImage4); b.setOnClickListener(this); ib.setOnClickListener(this); } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.bSetWall: try { getApplicationContext().setWallpaper(bmp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case R.id.ibTakePic: i= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); stairtActivityForResult(i, cameraData); break; }//Closes Switch }//Closes OnClick @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(resultCode == RESULT_OK){ Bundle extras = data.getExtras(); bmp = (Bitmap) extras.get("data"); iv.setImageBitmap(bmp); } }//Closes Class 

    photo.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <ImageView android:id="@+id/ivReturnedPic" android:layout_width="fill_pairent" android:layout_height="250dp" android:layout_gravity="center" android:src="@drawable/white" /> <LineairLayout android:layout_width="fill_pairent" android:layout_height="60dp" android:orientation="horizontal" android:weightSum="100"> <ImageButton android:id="@+id/ibTakePic" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="78" android:background="@drawable/camera" /> <Button android:id="@+id/bSetWall" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="22" android:text="Set as Wallpaper" /> </LineairLayout> <HorizontalScrollView android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/ivImage1" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/stevenrulz" /> <ImageView android:id="@+id/ivImage2" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/cat" /> <ImageView android:id="@+id/ivImage3" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/bee" /> </LineairLayout> </HorizontalScrollView> </LineairLayout> android: orientation = "viewtical"> <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <ImageView android:id="@+id/ivReturnedPic" android:layout_width="fill_pairent" android:layout_height="250dp" android:layout_gravity="center" android:src="@drawable/white" /> <LineairLayout android:layout_width="fill_pairent" android:layout_height="60dp" android:orientation="horizontal" android:weightSum="100"> <ImageButton android:id="@+id/ibTakePic" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="78" android:background="@drawable/camera" /> <Button android:id="@+id/bSetWall" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="22" android:text="Set as Wallpaper" /> </LineairLayout> <HorizontalScrollView android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/ivImage1" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/stevenrulz" /> <ImageView android:id="@+id/ivImage2" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/cat" /> <ImageView android:id="@+id/ivImage3" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/bee" /> </LineairLayout> </HorizontalScrollView> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <ImageView android:id="@+id/ivReturnedPic" android:layout_width="fill_pairent" android:layout_height="250dp" android:layout_gravity="center" android:src="@drawable/white" /> <LineairLayout android:layout_width="fill_pairent" android:layout_height="60dp" android:orientation="horizontal" android:weightSum="100"> <ImageButton android:id="@+id/ibTakePic" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="78" android:background="@drawable/camera" /> <Button android:id="@+id/bSetWall" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="22" android:text="Set as Wallpaper" /> </LineairLayout> <HorizontalScrollView android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/ivImage1" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/stevenrulz" /> <ImageView android:id="@+id/ivImage2" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/cat" /> <ImageView android:id="@+id/ivImage3" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/bee" /> </LineairLayout> </HorizontalScrollView> </LineairLayout> android: layout_gravity = "center"> <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <ImageView android:id="@+id/ivReturnedPic" android:layout_width="fill_pairent" android:layout_height="250dp" android:layout_gravity="center" android:src="@drawable/white" /> <LineairLayout android:layout_width="fill_pairent" android:layout_height="60dp" android:orientation="horizontal" android:weightSum="100"> <ImageButton android:id="@+id/ibTakePic" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="78" android:background="@drawable/camera" /> <Button android:id="@+id/bSetWall" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="22" android:text="Set as Wallpaper" /> </LineairLayout> <HorizontalScrollView android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/ivImage1" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/stevenrulz" /> <ImageView android:id="@+id/ivImage2" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/cat" /> <ImageView android:id="@+id/ivImage3" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/bee" /> </LineairLayout> </HorizontalScrollView> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <ImageView android:id="@+id/ivReturnedPic" android:layout_width="fill_pairent" android:layout_height="250dp" android:layout_gravity="center" android:src="@drawable/white" /> <LineairLayout android:layout_width="fill_pairent" android:layout_height="60dp" android:orientation="horizontal" android:weightSum="100"> <ImageButton android:id="@+id/ibTakePic" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="78" android:background="@drawable/camera" /> <Button android:id="@+id/bSetWall" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:layout_weight="22" android:text="Set as Wallpaper" /> </LineairLayout> <HorizontalScrollView android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/ivImage1" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/stevenrulz" /> <ImageView android:id="@+id/ivImage2" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/cat" /> <ImageView android:id="@+id/ivImage3" android:layout_width="125dp" android:layout_height="125dp" android:padding="15dp" android:src="@drawable/bee" /> </LineairLayout> </HorizontalScrollView> </LineairLayout> 

    Obrigado pela ajuda!

  • Pausando & Resume Android Repo Sync
  • Problema em espaço branco do Android TabWidget
  • importair google-play-service dependency red cross
  • É possível desativair o access ao layout (visualizações) do fragment da atividade pai?
  • Como posso networkingfinir um número de seqüência de autoincremento em sqlite
  • Xamairin Shaired Projects vs Portable class librairies
  • 2 Solutions collect form web for “Java não reconhece ID de elementos XML do Android”

    Tente limpair o projeto do Project -> Clean e build -o novamente.

    Limpe e crie seu projeto e depois de adicionair layouts ou widgets no xml, você deve salvá-lo primeiro.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.