Fehler ohne Sinn? java.lang.RuntimeException: Unable to start activity ComponentInfo

M4RC2

Mitglied
Hallo Leute,


ich bin zwar kein Profi, aber ich habe hier einen Fehler vor mir der bei ca 70% meiner AppNutzer auftaucht! Immer derselbe! Auf meinem Handy funktioniert alles :/

Erstmal hier der Fehler:
Code:
java.lang.RuntimeException: Unable to start activity ComponentInfo{m4rc.de.dichtometer/m4rc.de.dichtometer.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at m4rc.de.dichtometer.MainActivity.calc(MainActivity.java:162)
at m4rc.de.dichtometer.MainActivity.onCreate(MainActivity.java:60)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
... 11 more

Aus dem Fehler hab ich 2 Dinge entnommen:
at m4rc.de.dichtometer.MainActivity.calc(MainActivity.java:162)
at m4rc.de.dichtometer.MainActivity.onCreate(MainActivity.java:60)

Mit dem Rest kann ich nichts anfangen...

at m4rc.de.dichtometer.MainActivity.calc(MainActivity.java:162)
In dieser Zeile steht folgendes: TextView bier05tv = (TextView) findViewById(R.id.output05); bier05tv.setText("" + bier05);


Das Textview aus XML:
Code:
    <TextView
        android:id="@+id/output05"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/bier05button"
        android:layout_below="@+id/bier05button"
        android:text="@+id/b05t" />

In Eclipse wird die ID gefunden und zugeordnet! Ich habe keine Fehler und auch "bier05" wird ordentlich definiert:
int bier05 = getSharedPreferences("bier05", MODE_PRIVATE).getInt("bier05", 0);



Der andere Fehler den ich herausgefiltert habe (Zeile 60) ist eine "Verlinkung" auf "calc()"
Da sich der erste Fehler in calc() befindet, gehe ich davon aus, dass das nur eine Reaktion auf diesen Fehler war...


Ich würde ungern meinen kompletten Code hier im Forum teilen.
Falls es nicht anders geht, bin ich aber bereit es zutun....


Wer hat eine Idee?`


Marc
 

VfL_Freak

Top Contributor
Moin,

das Enstscheidende sind die beiden ersten Zeilen!

Es fliegt eine NullPointerException (d. h. "irgendwas" ist NULL) und zwar hier:
ActivityThread.java:2295

Mehr kann ich Dir ohne den relevanten Code auch nicht sagen ....

Gruß
Klaus
 

dzim

Top Contributor
Sorry @VfL_Freak, dass ich widersprechen muss, aber das entscheidende sind nicht die ersten beiden Zeilen, sondern diese hier:
Code:
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at m4rc.de.dichtometer.MainActivity.calc(MainActivity.java:162)
at m4rc.de.dichtometer.MainActivity.onCreate(MainActivity.java:60)

@M4RC2: Ich muss mich fragen, ob du schon mal Stacktraces gelesen hast, denn genauer als das hier, geht es schon nicht mehr! o_O

Ich kenne das grundsätzliche Problem aber: Die App, die ich weiter entwickle hatte vor kurzem auch eine Reihe von Crashes, die ich nicht nachvollziehen konnte. Am Ende habe ich alle Fälle von möglichen und unmöglichen NullPointerExceptions abgefangen. der Code wurde dadurch wirklich eklig, aber am Ende hatte es keine Abstürze mehr. Immerhin etwas gutes ist bei der Aktion herausgekommen.
 

hauptDev

Bekanntes Mitglied
Also die calc Methode müsste man schon mal sehen um evtl. genaueres sagen zu können. Tritt das denn nur bei bestimmten Versionen/Modellen auf?

Gesendet von meinem Cat Tablet PHOENIX 8.1J0 mit Tapatalk
 

M4RC2

Mitglied
Okay, ich gebe mal meinen Code Preis:
Es gibt übrigens keine Gemeinsamkeiten bezüglich der Fehler! Auf manchen Smartphones läufts, auf anderen nicht!

Java:
/*
 * W A T S O N - A L G O R I T H M U S
Variablen
a	 = 	Alter in Jahren
s	 = 	Größe in cm
w	 = 	Gewicht in kg
f	 = 	Menge in ml
p	 = 	Alkoholgehalt des Getränks in Prozent
m	 = 	Mahlzeit
		1,0 = kleine Mahlzeit
		1,5 = normale Mahlzeit
		2,0 = grosse Mahlzeit
t	 = 	Zeit in Stunden nach dem letzten Getränk
b	 = 	Blutalkoholwert in Promille
Hilfs-Berechnung
männlich
  h = 2,447 - 0,0952 * a + 0,1074 * s + 0,3362 * w;
weiblich
  h = 0,203 - 0,07 * a + 0,1069 * s + 0,2466 * w;
Berechnung
b = 0,8 / h * ( f * p / 100 );

b = b - ( m + t ) * 0,1;
 * 
 * 
 * 
 */

package m4rc.de.dichtometer;



import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     
   
        
        startscreen();
        checksettings();
        calc();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //Menue
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return true;
    }
    
    public boolean onOptionsItemSelected(MenuItem item){

    	if(item.toString().equals("Einstellungen")){
    		setContentView(R.layout.settings);
    	}
    	if(item.toString().equals("Credits")){
    		setContentView(R.layout.credits);
    	}
    	if(item.toString().equals("Startseite")){
    		setContentView(R.layout.activity_main);
    	}
    	if(item.toString().equals("Reset")){
    		setContentView(R.layout.reset);
    	}
    return true;
    }
    
    public void startscreen(){
    	int a = getSharedPreferences("settings", MODE_PRIVATE).getInt("years", 0);
        int s = getSharedPreferences("settings", MODE_PRIVATE).getInt("cm", 0);
        String eingabe = getSharedPreferences("settings", MODE_PRIVATE).getString("sex", "0");
        
        TextView setanzeige = (TextView) findViewById(R.id.setanzeige1); setanzeige.setText("" + a + " Jahre - " + s + "cm - " + eingabe);
        
        timer("difference");
    
    }
    
    public void checksettings() {
    int checkold = getSharedPreferences("settings", MODE_PRIVATE).getInt("years", 0);
    if(checkold==0){
    	setContentView(R.layout.settings);
    }
    }
    public void Clickbier05(View view){
    	int name2 = getSharedPreferences("bier05", MODE_PRIVATE).getInt("bier05", 0);
    	int a = 1;
    	int newint = name2 + a;
    	getSharedPreferences("bier05", MODE_PRIVATE).edit().putInt("bier05", newint).commit(); 
    	calc();
    }
    
    public void Clickbier033(View view){
    	int name2 = getSharedPreferences("bier033", MODE_PRIVATE).getInt("bier033", 0);
    	int a = 1;
    	int newint = name2 + a;
    	getSharedPreferences("bier033", MODE_PRIVATE).edit().putInt("bier033", newint).commit(); 
    	calc();
    }
    
    public void Clickmas(View view){
    	int name2 = getSharedPreferences("mas", MODE_PRIVATE).getInt("mas", 0);
    	int a = 1;
    	int newint = name2 + a;
    	getSharedPreferences("mas", MODE_PRIVATE).edit().putInt("mas", newint).commit(); 
    	calc();
    }
    
    public void Clickwine(View view){
    	int name2 = getSharedPreferences("wine", MODE_PRIVATE).getInt("wine", 0);
    	int a = 1;
    	int newint = name2 + a;
    	getSharedPreferences("wine", MODE_PRIVATE).edit().putInt("wine", newint).commit(); 
    	calc();
    }
    
    public void Clicksekt(View view){
    	int name2 = getSharedPreferences("sekt", MODE_PRIVATE).getInt("sekt", 0);
    	int a = 1;
    	int newint = name2 + a;
    	getSharedPreferences("sekt", MODE_PRIVATE).edit().putInt("sekt", newint).commit(); 
    	calc();
    }
    
    public void Clickmischung(View view){
    	int name2 = getSharedPreferences("misch", MODE_PRIVATE).getInt("misch", 0);
    	int a = 1;
    	int newint = name2 + a;
    	getSharedPreferences("misch", MODE_PRIVATE).edit().putInt("misch", newint).commit(); 
    	calc();
    }

    public void calc(){
    	//Rechner
    	//int a = getSharedPreferences("settings", MODE_PRIVATE).getInt("years", 0);
    	//int s = getSharedPreferences("settings", MODE_PRIVATE).getInt("cm", 0);
    	int w = getSharedPreferences("settings", MODE_PRIVATE).getInt("gewicht", 0);
    	String eingabe = getSharedPreferences("settings", MODE_PRIVATE).getString("sex", "0");

        int bier05 = getSharedPreferences("bier05", MODE_PRIVATE).getInt("bier05", 0); 
        TextView bier05tv = (TextView) findViewById(R.id.output05); bier05tv.setText("" + bier05); //HIER IST DER FEHLER!!!
        
        int bier033 = getSharedPreferences("bier033", MODE_PRIVATE).getInt("bier033", 0);
        TextView bier033tv = (TextView) findViewById(R.id.output033); bier033tv.setText("" + bier033);
        
        int bier1 = getSharedPreferences("mas", MODE_PRIVATE).getInt("mas", 0);
        TextView bier1tv = (TextView) findViewById(R.id.output1); bier1tv.setText("" + bier1);
        
        //int wine = getSharedPreferences("wine", MODE_PRIVATE).getInt("wine", 0);
        //TextView winetv = (TextView) findViewById(R.id.outputwine); winetv.setText("" + wine);
        
        int mischung = getSharedPreferences("misch", MODE_PRIVATE).getInt("misch", 0);
        TextView mischungtv = (TextView) findViewById(R.id.outputmischung); mischungtv.setText("" + mischung);
        
        int sekt = getSharedPreferences("sekt", MODE_PRIVATE).getInt("sekt", 0);
        TextView sekttv = (TextView) findViewById(R.id.outputsekt); sekttv.setText("" + sekt);
    	
    	//int a=16; //Alter
    	//int w=60; //gewicht
    	//int s=170; //Größe in cm
    	//double f; //Menge in ml
    	//int p; //Alk in prozent
    	//double m=1.5;
    	//int t=1;
    	
    	DecimalFormat fcalc = new DecimalFormat("#0.00");
    	String male = "Männlich";
    			
    	if(eingabe.equals(male)) {
    		//double hm = 2.447 - 0.0952 * a + 0.1074 * s + 0.3362 * w;
    		
    		/*bier
    		f=((bier033 * 330)+(bier05 * 500)+(bier1*1000));
    		p=5;
    		double bcalc = 0.8 / hm * ( f * p / 100 );
    		double b1 = bcalc - ( m + t ) * 0.1;
    		
    		//sekt
    		f=sekt*200;
    		p=10;
    		double bcalc2 = 0.8 / hm * ( f * p / 100 );
    		double b2 = bcalc2 - ( m + t ) * 0.1;
    		
    		//mischung
    		f=mischung*20;
    		p=20;
    		double bcalc3 = 0.8 / hm * ( f * p / 100 );
    		double b3 = bcalc3 - ( m + t ) * 0.1;*/
    		
    		//Gramm alk - 
    		double bgesamt1 = (0.8 * ((((bier033 * 330)+(bier05 * 500)+(bier1*1000)) * 5 / 100 )+( (sekt*150) * 10 / 100 )+( (mischung*20) * 200 / 100 )));
    		double bgesamt = bgesamt1 / (0.7 * w);
    		
    		//double bgesamt = b1+b2+b3;
    		TextView promille = (TextView) findViewById(R.id.ptextview); promille.setText("Promille " + fcalc.format(bgesamt));
    	}
    	
    	
    	else {
    		
    		double bgesamt1 = (0.8 * ((((bier033 * 330)+(bier05 * 500)+(bier1*1000)) * 4.8 / 100 )+( (sekt*150) * 10 / 100 )+( (mischung*20) * 200 / 100 )));
    		double bgesamt = bgesamt1 / (0.6 * w);
    		TextView promille = (TextView) findViewById(R.id.ptextview); promille.setText("Promille " + fcalc.format(bgesamt));
    	}
    }
    	

    
    public void setsettings(View view){
    	RadioGroup g = (RadioGroup) findViewById(R.id.radioSex); 
    	int selected = g.getCheckedRadioButtonId();
    	RadioButton b = (RadioButton) findViewById(selected);
    	String eingabe = (String) b.getText();
    	String male = "Männlich";
    			
    	if(eingabe.equals(male)){
    		getSharedPreferences("settings", MODE_PRIVATE).edit().putString("sex", "Männlich").commit();
    	} else {
    		getSharedPreferences("settings", MODE_PRIVATE).edit().putString("sex", "Weiblich").commit();
    	}
    	
    	//Jahre
    	EditText et = (EditText)findViewById(R.id.yearsid);
    	int jahre = Integer.parseInt(et.getText().toString());
    	getSharedPreferences("settings", MODE_PRIVATE).edit().putInt("years", jahre).commit();
    	
    	//Größe
    	EditText etg = (EditText)findViewById(R.id.groseid);
    	int grose = Integer.parseInt(etg.getText().toString());
    	getSharedPreferences("settings", MODE_PRIVATE).edit().putInt("cm", grose).commit();
    	
    	//Gewicht
    	EditText etgw = (EditText)findViewById(R.id.gewicht);
    	int gewichtvar = Integer.parseInt(etgw.getText().toString());
    	getSharedPreferences("settings", MODE_PRIVATE).edit().putInt("gewicht", gewichtvar).commit();
    
    	setContentView(R.layout.activity_main);
    	calc();
    }
    
   public void Resetall(View view) {
    	int resetnumber=0;
    	getSharedPreferences("bier05", MODE_PRIVATE).edit().putInt("bier05", resetnumber).commit();
    	getSharedPreferences("bier033", MODE_PRIVATE).edit().putInt("bier033", resetnumber).commit();
    	getSharedPreferences("mas", MODE_PRIVATE).edit().putInt("mas", resetnumber).commit();
    	getSharedPreferences("wine", MODE_PRIVATE).edit().putInt("wine", resetnumber).commit();
    	getSharedPreferences("misch", MODE_PRIVATE).edit().putInt("misch", resetnumber).commit();
    	getSharedPreferences("sekt", MODE_PRIVATE).edit().putInt("sekt", resetnumber).commit();
    	setContentView(R.layout.activity_main);
    }

   @SuppressLint("SimpleDateFormat") 
   public void timer(String cmd){
	   if(cmd.equals("start")) {
		   /*SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyy HH:mm:ss");
		   String currentDateandTime = sdf.format(new Date());*/
	   }
	   if(cmd.equals("difference")) {
		   		   
		   SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyy HH:mm:ss");
		   String dateStart = sdf.format(new Date());
		   
				//String dateStart = "01/14/2012 09:29:58";
				String dateStop = "01/15/2015 10:31:48";
		 
				//HH converts hour in 24 hours format (0-23), day calculation
				SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
		 
				Date d1 = null;
				Date d2 = null;
		 
				try {
					d1 = format.parse(dateStart);
					d2 = format.parse(dateStop);
		 
					//in milliseconds
					long diff = d2.getTime() - d1.getTime();
		 
					long diffSeconds = diff / 1000 % 60;
					long diffMinutes = diff / (60 * 1000) % 60;
					long diffHours = diff / (60 * 60 * 1000) % 24;
					long diffDays = diff / (24 * 60 * 60 * 1000);
		 
					String outputtimer = diffDays + " days, " + diffHours + " hours, " + diffMinutes + " minutes, " + diffSeconds + " seconds.";
					//TextView promille = (TextView) findViewById(R.id.timeranzeige); promille.setText("" + outputtimer);
		 
				} catch (Exception e) {
					e.printStackTrace();
				}
		 
			
	   }
   }

}

[XML]<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="566dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >

<ImageButton
android:id="@+id/bier05button"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="40dp"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:eek:nClick="Clickbier05"
android:scaleType="fitCenter"
android:src="@drawable/bier05" />

<TextView
android:id="@+id/output033"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/output05"
android:layout_alignLeft="@+id/bier033button"
android:layout_alignRight="@+id/bier033button"
android:layout_below="@+id/bier033button"
android:text="@+id/b033t" />

<TextView
android:id="@+id/ptextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:text="@string/promillebox" />

<ImageButton
android:id="@+id/bier033button"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_above="@+id/output05"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:eek:nClick="Clickbier033"
android:scaleType="fitCenter"
android:src="@drawable/bier03" />

<ImageButton
android:id="@+id/mas"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/bier033button"
android:layout_marginRight="14dp"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:eek:nClick="Clickmas"
android:scaleType="fitCenter"
android:src="@drawable/mas" />

<TextView
android:id="@+id/output1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/mas"
android:layout_below="@+id/mas"
android:text="@+id/b1t" />

<ImageButton
android:id="@+id/ImageButton03"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignLeft="@+id/output033"
android:layout_below="@+id/output033"
android:layout_marginTop="22dp"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:eek:nClick="Clicksekt"
android:scaleType="fitCenter"
android:src="@drawable/sekt" />

<TextView
android:id="@+id/outputsekt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ImageButton03"
android:layout_centerHorizontal="true"
android:text="@+id/sektt" />

<TextView
android:id="@+id/outputmischung"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/outputsekt"
android:layout_alignBottom="@+id/outputsekt"
android:layout_alignLeft="@+id/nope"
android:layout_alignParentRight="true"
android:text="@+id/mischungt" />

<ImageButton
android:id="@+id/nope"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignLeft="@+id/output1"
android:layout_alignTop="@+id/ImageButton03"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:eek:nClick="Clickmischung"
android:scaleType="fitCenter"
android:src="@drawable/mischung" />

<TextView
android:id="@+id/setanzeige1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/output05"
android:layout_alignParentBottom="true"
android:layout_marginBottom="14dp"
android:text="@string/anzeige" />

<TextView
android:id="@+id/output05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/bier05button"
android:layout_below="@+id/bier05button"
android:text="@+id/b05t" />

<TextView
android:id="@+id/timeranzeige"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/setanzeige1"
android:layout_toLeftOf="@+id/outputsekt"
android:text="@string/timertext" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/timeranzeige"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="@string/mainmenu"
android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>
</ScrollView>[/XML]

[XML]<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:id="@+id/activity_main" android:title="@string/mainmenu"></item><item
android:id="@+id/action_settings"
android:eek:rderInCategory="100"
android:title="@string/action_settings"/>
<item android:id="@+id/credits" android:title="@string/credits"></item>
<item android:id="@+id/reset" android:title="@string/reset"></item>


</menu>
[/XML]

[XML]<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Dichtometer</string>
<string name="action_settings">Einstellungen</string>
<string name="radio_female">Weiblich</string>
<string name="radio_male">Männlich</string>
<string name="size">Größe</string>
<string name="alter">Alter</string>
<string name="mw">Mannsweib</string>
<string name="headereinstellungen">Einstellungen</string>
<string name="credits">Credits</string>
<string name="credittext1">Programmiert von M4RC.DE</string>
<string name="credittext2">Design by Matthias D.</string>
<string name="mainmenu">Startseite</string>
<string name="bier05button">Bier 0,5L</string>
<string name="desc">desc</string>
<string name="promillebox">Promille: </string>
<string name="testview">Testview</string>
<string name="saveit">Speichern</string>
<string name="years">Jahre</string>
<string name="cm">cm</string>
<string name="reset">Reset</string>
<string name="anzeige">Bitte restarte die App</string>
<string name="gewicht">Gewicht</string>
<string name="kg">kg</string>
<string name="timertext">Timer wartet</string>

</resources>
[/XML]


Ich denke das ist alles was ihr braucht oder?
 

dzim

Top Contributor
Naja. "bier05tv" ist dann weisste das doch schon. Ich finde es nur schräg, dass du die beide auf einer Zeile schreibst. macht es nicht leichter, durchzuschauen.
BTW: im Java-Codeclock kannst du auch die Zeilennummern explizit angeben, dann musst du nicht die ganze Klasse posten. (Steht oberhalb der "Direktantwort"-Box drüber
Code:
[ JAVA=42 ]hier Codeausschnitt einfügen[ /JAVA ]
.
 
Zuletzt bearbeitet:

M4RC2

Mitglied
Ist hier im Forum nur falsch formatiert! Ist eigentlich auch so! Löst trotzdem nicht den Fehler :/

Gesendet von meinem ST27i mit Tapatalk
 

dzim

Top Contributor
Der Grund ist übrigens vermutlich recht einfach: Die #calc-Methode wird vermutlich VOR der Initialisierung des UIs selbst aufgerufen.
Mein Tipp: in #onCreate, nachdem du den contentView gesetzt hast, hole alle deine TextViews etc. über findeViewById und speichere sie in private Member-Variablen (
Code:
private TextView mBier05tv;
). Und vor dem setzen testet du ob die UI schon da ist, indem du einen Check machst, ob der TextView != null ist... Einfacher geht's ja nicht :)
 

dzim

Top Contributor
Sag mal, hast du eigentlich schon mal von CamelCase gehört? Irgendwie schreibst du deine Methoden und alles auch jedes mal anders...
Klassennamen: CamelCase
Methoden-/Variablen: camelCase
 

VfL_Freak

Top Contributor
Moin,

was dzim sagen wollte ist, dass uns nun nicht klar ist, in welcher Zeile denn nun die NPE auftritt ...

Hier:
Java:
TextView bier05tv = (TextView) findViewById(R.id.output05);

oder doch eher hier:
Java:
bier05tv.setText("" + bier05);
Wenn es der zweite Fall ist (was ichmal vermute), dann ist halt "bier05 == null" !!

Gruß
Klaus
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
W Navigation MenuItem Switch Fehler Android & Cross-Platform Mobile Apps 6
J Das Beispiel von Android erzeugt Fehler Android & Cross-Platform Mobile Apps 8
W Volley onDestroy angemeldet bleiben Fehler... unabhänging vom Login Android & Cross-Platform Mobile Apps 37
P undefinierbarer Fehler Android Android & Cross-Platform Mobile Apps 8
M INSTALL_FAILED_OLDER_SDK - Was muß ich tun damit der Fehler verschwindet Android & Cross-Platform Mobile Apps 8
lolcore android studio: fehler bei laden des emulators Android & Cross-Platform Mobile Apps 10
T Fehler Android Studio: java.net.MalformedURLException: no protocol: http%3A%2F%2Fwww.mal ..... Android & Cross-Platform Mobile Apps 2
Arif Android Android Studio: Fehler beim Einbinden fremder Bibliothek? Android & Cross-Platform Mobile Apps 2
J error: <identifier> expected error: illegal start of type "Wo ist der Fehler?" Android & Cross-Platform Mobile Apps 5
G Gluon Fehler Meldung Android & Cross-Platform Mobile Apps 4
B Android App Fehler Android & Cross-Platform Mobile Apps 21
JavaWolf165 Android Fehler beim Speichern/Downloaden einer Datei Android & Cross-Platform Mobile Apps 2
R Android Wie kann ich diesen Fehler beheben? Android & Cross-Platform Mobile Apps 10
M Android Fehler beim Parsen. Android & Cross-Platform Mobile Apps 29
S IF Anweisung zeigt Fehler trotz richtiger Eingabe? Android & Cross-Platform Mobile Apps 7
S Fehler beim Textdatei einlesen!? Android & Cross-Platform Mobile Apps 7
A Mehrere Fehler beim Compilieren Android & Cross-Platform Mobile Apps 4
H Fehler bei leerem TextEdit Android & Cross-Platform Mobile Apps 4
H Fehler Actionbar Theme ändern Android & Cross-Platform Mobile Apps 2
J Wo liegt der Fehler? Android & Cross-Platform Mobile Apps 0
G Fehler beim Import "Invalid project description" Android & Cross-Platform Mobile Apps 2
A Fehler beim Starten eines Intents - alles in einer Klasse funktioniert... Android & Cross-Platform Mobile Apps 4
C Java ME Fehler JSR-172 Android & Cross-Platform Mobile Apps 3
F Bilder in Java importieren (Fehler?) Android & Cross-Platform Mobile Apps 5
Apo Android Dx bad class Fehler Android & Cross-Platform Mobile Apps 4
F Android Fehler in Spinner Android & Cross-Platform Mobile Apps 3
S Android Fehler beim Anzeigen meines Apps auf Galaxy Tab Android & Cross-Platform Mobile Apps 4
J Fehler: Unbehandelte Ausnahme Android & Cross-Platform Mobile Apps 8
A Midlet bei Fehler elegant beenden mit Fehlermeldung Android & Cross-Platform Mobile Apps 4
S Compiler Fehler Android & Cross-Platform Mobile Apps 2
B Fehler bei Midlet installation? "Aktion Abgebrochen&quo Android & Cross-Platform Mobile Apps 10
Naxon89 Duplicate class kotlin - und dies ohne das es angewendet wird Android & Cross-Platform Mobile Apps 1
I Android ListView, Werte aktualisieren ohne die Liste komplett neu zu laden Android & Cross-Platform Mobile Apps 5
T Screenshot speichern ohne alte Datei überschreiben Android & Cross-Platform Mobile Apps 3
T Android ArrayList sortieren mit 2 Werten ohne thencomparing , Wie? Android & Cross-Platform Mobile Apps 10
Jackii Android Android Studio Error im Testlauf ohne zu programmieren Android & Cross-Platform Mobile Apps 9
L Android App ohne MainActivity Android & Cross-Platform Mobile Apps 3
J Android LogIn/Registrierung ohne Mail-Adresse Android & Cross-Platform Mobile Apps 1
B Android USB Debugging ohne kabel möglich? Android & Cross-Platform Mobile Apps 5
G Accelerometer ohne Activity Android & Cross-Platform Mobile Apps 8
G Activity-Wechsel bitte ohne Notification Android & Cross-Platform Mobile Apps 6
G Pause ohne sleep und ohne zweiten Thread Android & Cross-Platform Mobile Apps 5
G Pause im Programmablauf ohne extra Thread Android & Cross-Platform Mobile Apps 2
C Activity ohne Aktion starten Android & Cross-Platform Mobile Apps 8
S Entwicklung von Smartphone programmen ohne selber eins zu besitzen Android & Cross-Platform Mobile Apps 17
StrikeTom Android tabs ohne xml Android & Cross-Platform Mobile Apps 6

Ähnliche Java Themen

Neue Themen


Oben