Android Hilfe string to float geht nicht...

Status
Nicht offen für weitere Antworten.
N

.Niklas.

Gast
Hallo , ich bastel mir grade aus spaß ein rechen app für das handy wo ich dann die formeln die wir in mathe grade brauchen einprogrammieren kann nun habe ich das problem (und ich habe ehrlich gesagt keine ahnung wieso) das die String to Float methode die ich benutze ( Float x = new Float(jahre.getText().toString());) nicht funktioniert da bricht es schon vor "setContentView(R.layout.exponentiell);" ab
Hab erst vor 2 tagen angefangen das erste mal für android zu programmierung und kenne mich deswegen noch nicht so aus wäre nett wenn mir jemand helfen könnte :)


Java:
	public void zinsknopfmeth1(View view){

	   	EditText jahre = (EditText)findViewById(R.id.zinsjahr);
	  	EditText wert1 = (EditText)findViewById(R.id.zinswert1);
	  	EditText wert2 = (EditText)findViewById(R.id.zinswert2);
	  	EditText zinsenjahr = (EditText)findViewById(R.id.zinsausjahr);
	
	     Float x = new Float(jahre.getText().toString());
	     Float y = new Float(wert1.getText().toString());
	     Float z = new Float(wert2.getText().toString());
	     Float p = new Float(zinsenjahr.getText().toString());
	
	    if(y == 0 && z == 0 || x == 0 || p == 0 ){

	    		
	    		Context context = getApplicationContext();
	    		CharSequence text = "Dies geht nicht";
	    		int duration = Toast.LENGTH_SHORT;

	    		Toast toast = Toast.makeText(context, text, duration);
	    		
	    		toast.show();
	    		
	    		return;
	    		}
	    		
	    	setContentView(R.layout.exponentiell);
	       	ListView llosung = (ListView) findViewById(R.id.listView1);
	       	llosung.setAdapter(null);
	     zinsmeth1(x, y ,z ,p);
	     ArrayAdapter<String> adapterLosung = new ArrayAdapter<String>(RechnerVersuchActivity.this,android.R.layout.simple_list_item_1, hallo);
	     
	     
	 	
	     llosung.setAdapter(adapterLosung);
	     
	}

Mfg Niklas
 
N

.Niklas.

Gast
Sry wegen doppel post aber wollte noch hinzu fügen das sobald werte in den text boxe stehen es nicht mehr funktioniert kann es vielleicht daran liegen das ich relative layouts benutzt habe? wenn über all 0 steht kommt nur NaN
 

Marco13

Top Contributor
Die LogCat sollte da doch zumindest sagen, was schiefgegangen ist. Vermutlich eine NumberFormatException? Lass dir ggf. den String mal ausgeben, bevor du ihn in einen Float verwandeln willst
 

Hobelhai

Mitglied
Wie wäre es denn mit
Java:
Float x = new Float(Float.parseFloat(jahre.getText().toString()));
 

eRaaaa

Top Contributor
Ich denke viel eher dass eine NPE fliegt, weil du zuerst die ContentView mit setContentView setzen musst, erst anschließend kannst du auf die anderen Views wie z.B. EditText zugreifen! Vorher sind diese nicht verfügbar(null)
(Versetze Zeile 27 also beispielsweise in die onCreate!)

/EDIT: Oh, sehe gerade dass hier wieder ein alter Thread ausgegraben wurde! Hier ist erst mal zu, sollte der TO den Thread doch nochmal gebrauchen, kann er sich bei einen der Mods melden.
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
M Android Kotlin: Bitte dringend um Hilfe Android & Cross-Platform Mobile Apps 2
Mo1234 Plattform in einer App. Bitte um Hilfe! Android & Cross-Platform Mobile Apps 8
M Hilfe bei App Programmierung für Android Android & Cross-Platform Mobile Apps 1
A Fehlermeldung, brauche Hilfe. Android & Cross-Platform Mobile Apps 2
D Hilfe! es geht um Buttons und Sounds Android & Cross-Platform Mobile Apps 14
P Brauche Hilfe bei Code Snippet Android & Cross-Platform Mobile Apps 10
L Android Hilfe bei Passwort einlesen Android & Cross-Platform Mobile Apps 5
M Telefonbuch in J2ME programmieren HILFE! Android & Cross-Platform Mobile Apps 34
R Fehlersuche - brauche eure Hilfe Android & Cross-Platform Mobile Apps 10
W UTF-8 String Android & Cross-Platform Mobile Apps 66
W Base64 konvertierter URI String Android & Cross-Platform Mobile Apps 32
W String Array Pfad in Int setzen Android & Cross-Platform Mobile Apps 54
W Volley String Response gibt falchen if aus Android & Cross-Platform Mobile Apps 35
H Anfänger String types not allowed (at 'textColor' with value 'black' Android & Cross-Platform Mobile Apps 13
W Firestore String in Apps Laden Android & Cross-Platform Mobile Apps 10
T Android R.string.test+i Problem Android & Cross-Platform Mobile Apps 2
A Mit Java neues item in ein string-array einer Strings.xml schreiben Android & Cross-Platform Mobile Apps 4
C Zugriff auf die Position eines String- bzw Spinner-Arrays Android & Cross-Platform Mobile Apps 1
J Android String in andere Java-Dateien überführen Android & Cross-Platform Mobile Apps 1
J R.string.(variable) geht das Android & Cross-Platform Mobile Apps 3
R Android incomingNumber bein Eingehenden Anruf immer leerer String Android & Cross-Platform Mobile Apps 4
S SPLIT funktion bei STRING funktioniert nicht! Android & Cross-Platform Mobile Apps 4
G String an einen php Script senden Android & Cross-Platform Mobile Apps 8
J Plötzlich "java.lang.String cannot be converted to JSONObject" Android & Cross-Platform Mobile Apps 9
T int to string ... Android & Cross-Platform Mobile Apps 8
A String[] für Lisadapter Android & Cross-Platform Mobile Apps 4
M jsonobject cannot be cast to java.lang.string Android & Cross-Platform Mobile Apps 4
J Einen String bewegen wie? Android & Cross-Platform Mobile Apps 3
R String wie WAV Datei nutzen Android & Cross-Platform Mobile Apps 4
C 2 kleine Probleme (Datei lesen, String durchsuchen) Android & Cross-Platform Mobile Apps 16
L String dem Display anpassen Android & Cross-Platform Mobile Apps 12
G Text parsen String to Double Android & Cross-Platform Mobile Apps 2
S ein String nach vorgegebenen Zeichen teilen Android & Cross-Platform Mobile Apps 3
N Zeichen im String löschen? Android & Cross-Platform Mobile Apps 18
M MIDlet + Datum in String Android & Cross-Platform Mobile Apps 5
R float parsen Android & Cross-Platform Mobile Apps 2
S Double und Float im WTK? Android & Cross-Platform Mobile Apps 7

Ähnliche Java Themen

Neue Themen


Oben