anis25 Posted February 28, 2013 Share Posted February 28, 2013 bonjour je debut dans la programation android j'ai un petit problem une erreur "text cannot be resolved" j'ai suivie ce tuto http://www.vogella.c...id/article.html voici le mainacivity.java package com.anis.android.measureconverter;[/url] [url="http://www.vogella.com/articles/Android/article.html"]import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.RadioButton; import android.widget.Toast;[/url] [url="http://www.vogella.com/articles/Android/article.html"]public class MainActivity extends Activity {[/url] [url="http://www.vogella.com/articles/Android/article.html"]@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }[/url] [url="http://www.vogella.com/articles/Android/article.html"]@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }[/url] [url="http://www.vogella.com/articles/Android/article.html"]// This method is called at button click because we assigned the name to the // "onclick property" of the button public void onclick(View view) { switch (view.getId()) { case R.id.button1: RadioButton centimetreButton = (RadioButton) findViewById(R.id.radio0); RadioButton pouceButton = (RadioButton) findViewById(R.id.radio1); if (text.getText().length() == 0) { Toast.makeText(this, "Entrez Une valeur", Toast.LENGTH_LONG).show(); return; }[/url] [url="http://www.vogella.com/articles/Android/article.html"] float inputValue = Float.parseFloat(text.getText().toString()); if (centimetreButton.isChecked()) { text.setText(String .valueOf(convertPouceToCentimetre(inputValue))); centimetreButton.setChecked(false); pouceButton.setChecked(true); } else { text.setText(String .valueOf(convertCentimetreToPouce(inputValue))); pouceButton.setChecked(false); centimetreButton.setChecked(true); } break; } }[/url] [url="http://www.vogella.com/articles/Android/article.html"]// Converts to centimetre private float convertPouceToCentimetre(float pouce) { return ((pouce * 254) / 100); }[/url] [url="http://www.vogella.com/articles/Android/article.html"]// Converts to pouce private float convertCentimetreToPouce(float centimetre) { return ((centimetre * 100) / 254); } } Link to comment Share on other sites More sharing options...
arnouf Posted March 6, 2013 Share Posted March 6, 2013 bonjour je debut dans la programation android j'ai un petit problem une erreur "text cannot be resolved" j'ai suivie ce tuto http://www.vogella.c...id/article.html text est un variable dans ta méthode onclick qui ne semble pas avoir été déclarée ailleurs dans ton code. Dans le fichier activity_main tu dois avoir une élément de type TextView ou EditText. Au dessus de onCreate.... ajoute un element de type TextView ou EditText (en fonction de ce que tu dis au dessus) TextView text; Dans ton code java, après le setcontentview dans la méthode onCreate text = (TextView)findViewById(R.id.identifiant_du_textview_dans_fichier_xml_reprensenté_apres_android:id); Normalement ça devrait être bon. Je te conseille avant d'aller plus loin : - regarder les bases du langage Java - ne vise pas dans un premier temps ce que tu souhaites faire, mais avance petit à petit Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.