Android Eine Kleinigkeit für Profis

L

labbes

Gast
Hallo zusammen,

ich habe mich heute mal rangewagt an eine kleine Taschenrechner Programmierung und bekomme eine Fehler bei dem ich einfach nicht weiter komme.
Ich denke das ist nichts schwieriges aber manchmal sieht man den Wald vor lauter Bäumen nicht.

Ich bitte daher um einen Rat. Folgenden Fehler bekomme ich:

Cannot invoke setText(String) on the primitive type float


Java:
public class TaschnerechnerActivity extends Activity implements OnClickListener
{
    /** Called when the activity is first created. */
	TextView zahl1, zahl2, ergebniss;
	Button Bplus, Bminus, Bmal, Bdurch;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        zahl1=(TextView)findViewById(R.id.zahl1);
        zahl2=(TextView)findViewById(R.id.zahl2);
        ergebniss=(TextView)findViewById(R.id.ergebniss);
        
        Bplus=(Button)findViewById(R.id.Bplus);
        Bminus=(Button)findViewById(R.id.Bminus);
        Bmal=(Button)findViewById(R.id.Bmal);
        Bdurch=(Button)findViewById(R.id.bdurch);
        
        Bplus.setOnClickListener(this);
        Bminus.setOnClickListener(this);
        Bmal.setOnClickListener(this);
        Bdurch.setOnClickListener(this);
    }


	public void onClick(View arg0)
	{
		
		float z1=Float.parseFloat(zahl1.getText().toString());
		float z2=Float.parseFloat(zahl2.getText().toString());
		float ergebniss=0;
		
		if (arg0==Bplus){
			ergebniss=z1+z2;
			
		}
		
		if (arg0==Bminus){
			ergebniss=z1-z2;
			
		}
		if (arg0==Bmal){
			ergebniss=z1*z2;
			
		}
		if (arg0==Bdurch){
			ergebniss=z1/z2;
			
		}
		
		ergebniss.setText(""+ergebniss);
		
	
	}
}


Der Fehler taucht in der letzen Zeile auf.
Vielen Dank für eure Hilfe schonmal.
 

diel2001

Bekanntes Mitglied
versuch doch statt das
Java:
textFeld.setText(""+ergebniss);
dies
Java:
textFeld.setText(String.valueOf(ergebniss));
benenn dies mal um
Java:
float ergebniss=0;

Du hast eine innere Variable, die ergebniss heißt und eine Klassenvariable.
Und da nimmt er zuerst die innere Variable und kann der natürlich nichts zuweisen.
 
Zuletzt bearbeitet:
Ähnliche Java Themen
  Titel Forum Antworten Datum
L Android Wie erstelle ich eine dynamische Tabelle (TableLayout)? Android & Cross-Platform Mobile Apps 2
W Zur Laufzeit erstelltes MenuItem an eine View binden Android & Cross-Platform Mobile Apps 1
J Android Zugriff auf eine Datei, diese von einer anderen App erstellt wurde? Android & Cross-Platform Mobile Apps 11
W Pixel Farbe in eine andere Farbe ändern im ImageView von ein Icon Android & Cross-Platform Mobile Apps 14
S Sinnvollste weg eine SQLite DB mit Android auslesen Android & Cross-Platform Mobile Apps 7
L Regelmäßig eine Methode im Hintergund ausführen Android & Cross-Platform Mobile Apps 1
J Android Wann ist eine App privat? Android & Cross-Platform Mobile Apps 10
M Android Schreiben von JsonDaten in eine SqliteDB Android & Cross-Platform Mobile Apps 7
M Suche eine Webseite mit dem aktuelle Datum in XML Android & Cross-Platform Mobile Apps 18
R Android Eine Website-frame in einer App Android & Cross-Platform Mobile Apps 4
Robat Android Wie mache ich eine App mit verschiedenen Leveln? Android & Cross-Platform Mobile Apps 8
M [Android] Wie erstellt man eine Verknüpfung eines Ordners? Android & Cross-Platform Mobile Apps 7
R [ANDROID] Dynamisch eine Liste erweitern Android & Cross-Platform Mobile Apps 3
K Verständisfrage bzgl. Buttons und ihnen eine Funktion geben. Android & Cross-Platform Mobile Apps 3
X Android Wo gibts eine SortableListView? Android & Cross-Platform Mobile Apps 6
G eine Methode einer anderen Activity aufrufen Android & Cross-Platform Mobile Apps 9
S Android In Service überprüfen ob eine Activity gebunden ist? Android & Cross-Platform Mobile Apps 6
B TableLayout verhält sich nicht wie eine Tabelle Android & Cross-Platform Mobile Apps 3
A Android Eine Datei in Android löschen, aber wie ? Android & Cross-Platform Mobile Apps 24
A Koordinaten eine Images feststellen Android & Cross-Platform Mobile Apps 9
U [Android] Eine Datei aus Jar-Archiv laden Android & Cross-Platform Mobile Apps 4
N Gibt es eine opensource Speech-to-Text engine? Android & Cross-Platform Mobile Apps 3
B Android Eine Warnung in der Console (Eclipse) auswerten Android & Cross-Platform Mobile Apps 3
T Android Ergebnis eines XML+XSLT "transform" in eine HTML - Datei schreiben (Android) Android & Cross-Platform Mobile Apps 2
M Eclipse: cdc.jar in eine Midlet Suite integrieren Android & Cross-Platform Mobile Apps 18
L SecurityException beim lesen/schreiben eine Datei Android & Cross-Platform Mobile Apps 7
H Gibt es eine Alternative zur Location API? Android & Cross-Platform Mobile Apps 4
F Wie komplex wäre eine Wecker-Applikation? Android & Cross-Platform Mobile Apps 5
Kazudemruzo Android API/Library für externe Entwickler zur Verfügung stellen Android & Cross-Platform Mobile Apps 7
C Consent für Admob mit ump / funding choices Android & Cross-Platform Mobile Apps 6
B Was fehlt mir hier für diese Klasse? ich habe es mit (>>> ... <<<) markiert. Android & Cross-Platform Mobile Apps 4
J SharedPreferences für User-Session Android & Cross-Platform Mobile Apps 2
M Barrierefreie Appentwicklung für Android - Suche Codebeispiele Android & Cross-Platform Mobile Apps 8
I App für Fire HD entwickeln Android & Cross-Platform Mobile Apps 3
T Bringen mir die Java-Basics irgendetwas für die Android-Programmierung Android & Cross-Platform Mobile Apps 4
L Textfeld für Dezimalzahl mit Vorzeichen Android & Cross-Platform Mobile Apps 2
J Android Datenbank Klasse nur für CRUD-Operation, oder auch mehr ? Android & Cross-Platform Mobile Apps 8
B Android Projekt für Android und IOS erstellen? Android & Cross-Platform Mobile Apps 5
J Impressumspflicht für App, wenn ich kein Unternehmer bin? Android & Cross-Platform Mobile Apps 13
T Android Equalizer für Android Android & Cross-Platform Mobile Apps 3
L Zeitstempel für Sensordaten bekommen Android & Cross-Platform Mobile Apps 3
L Android Texterkennung für Android? Android & Cross-Platform Mobile Apps 1
L Android Chart API für Android Android & Cross-Platform Mobile Apps 0
T Android Datenbankverbindung in Service für Push Notification Android & Cross-Platform Mobile Apps 0
R Android USB Treiber für Huawei Android & Cross-Platform Mobile Apps 1
M Hilfe bei App Programmierung für Android Android & Cross-Platform Mobile Apps 1
B Script für Android Android & Cross-Platform Mobile Apps 1
H Datenprotokoll für Graphview Android & Cross-Platform Mobile Apps 2
M Android Obfuscation für Strings Android & Cross-Platform Mobile Apps 8
S Bilder mit fester grösse für verschiedene Android Endgeräte Android & Cross-Platform Mobile Apps 2
D Android Layout für alle Geräte Android & Cross-Platform Mobile Apps 4
A String[] für Lisadapter Android & Cross-Platform Mobile Apps 4
D Lib für (Desktop-)Java und Android schreiben Android & Cross-Platform Mobile Apps 7
J MySQL Simulation für Android App Android & Cross-Platform Mobile Apps 2
kaoZ Tutorial .xml Layouting für z.B ListView elemente Android & Cross-Platform Mobile Apps 7
W Java Editor für Android +Emulator Android & Cross-Platform Mobile Apps 7
M 20 Image Button für jede Auflösung positionieren Android & Cross-Platform Mobile Apps 3
L Android ActionBar mit unterschiedlichen Farben für Tabs Android & Cross-Platform Mobile Apps 3
S Voraussetzungen für Android-Apps Android & Cross-Platform Mobile Apps 7
R Sinnvoller Ablageort für Leveldaten Android & Cross-Platform Mobile Apps 8
B App bei Play-Store für bestimmte auflösungen anbieten? Android & Cross-Platform Mobile Apps 3
G extends Activity für Berechnungen? Android & Cross-Platform Mobile Apps 7
H Progrämmchen für Symbian Android & Cross-Platform Mobile Apps 4
G wiederkehrenden Wert für Design in XML ablegen Android & Cross-Platform Mobile Apps 2
L Android SearchBox für Custom Listview Android & Cross-Platform Mobile Apps 5
T Android KontrollApp für Nitrado Server Android & Cross-Platform Mobile Apps 2
G Android C++ Quellcode für Android Geräte compilieren Android & Cross-Platform Mobile Apps 2
T Zeit in zwei Zahlen für Widget zerlegen Android & Cross-Platform Mobile Apps 2
J Apps für Android programmieren - Android Handy notwendig oder reicht Simulator? Android & Cross-Platform Mobile Apps 3
A Android SimpleDateFormat gibt für Date unter android anderes Datum zurück als in Std. Java Android & Cross-Platform Mobile Apps 2
H Android Landscape Modus für App dektivieren Android & Cross-Platform Mobile Apps 3
M Frage zu Java Programm für Windows Mobile 6.5 Android & Cross-Platform Mobile Apps 2
H Welches JDK für Huawei G7002? Android & Cross-Platform Mobile Apps 6
C Panel/View für Android Android & Cross-Platform Mobile Apps 3
C Sanke für Android Android & Cross-Platform Mobile Apps 3
Kukulkan Welche Mindestanforderungen (JDK) für Android und BB? Android & Cross-Platform Mobile Apps 8
G Views für verschiedenen Bildschirmgroeßen Android & Cross-Platform Mobile Apps 2
thE_29 Widget für verpasste Anruf + SMS Android & Cross-Platform Mobile Apps 2
A Android Android Parameter für VM Android & Cross-Platform Mobile Apps 7
O Entwickler für Java Anwendungen auf Handy gesucht! Android & Cross-Platform Mobile Apps 3
S JButton in GUI für Handys? Android & Cross-Platform Mobile Apps 3
M Welche Datenbank für J2ME? Android & Cross-Platform Mobile Apps 5
D Event für Tastensperre? Android & Cross-Platform Mobile Apps 3
G WTK für Nokia Android & Cross-Platform Mobile Apps 2
P bestimmte API für XDA ORBIT2 Android & Cross-Platform Mobile Apps 3
S Idee gesucht für ein kleines Programm Android & Cross-Platform Mobile Apps 3
M ein image pixel für pixel aufbauen : setPixel() ? Android & Cross-Platform Mobile Apps 1
M Handyprogramm für U-Bahn-Fahrplan für Siemens SK65 Android & Cross-Platform Mobile Apps 2
J Empfehlungen für ME-Anfänger Android & Cross-Platform Mobile Apps 2
K Anwendung für Handy programmieren Android & Cross-Platform Mobile Apps 1
P Java für PDA DELL Axim 51 Android & Cross-Platform Mobile Apps 4
M Virtuelle Machiene für PDA Android & Cross-Platform Mobile Apps 8
B Programm für NokiaComunicator erstellen Android & Cross-Platform Mobile Apps 2
K Programme für Handy erstellen Android & Cross-Platform Mobile Apps 3
M Java-Programme für Handy auf Desktop-PC ausführen Android & Cross-Platform Mobile Apps 4
T Für Handy Game die Sprache umschreiben? Android & Cross-Platform Mobile Apps 24
M java game für handy mit grahi. oberfläche Android & Cross-Platform Mobile Apps 1
D java.security.MessageDigest (für ME?) Android & Cross-Platform Mobile Apps 1
N Unser Team such Coder für Spieleprojekte Android & Cross-Platform Mobile Apps 8
B WTK für Sony Ericsson? Android & Cross-Platform Mobile Apps 7

Ähnliche Java Themen

Neue Themen


Oben