Fehler beim Starten eines Intents - alles in einer Klasse funktioniert...

aquarium1974

Aktives Mitglied
Hallo Gemeinde,

ich zerlege gerade einen Code (der relativ Spaghetti-mäßig ist) in ein paar geeignete kleinere Klassen.

Leider bekomme ich jetzt einen Fehler:
Fehlermeldung:

[WR]
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): FATAL EXCEPTION: main
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): java.lang.NullPointerException
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at android.app.Activity.startActivityForResult(Activity.java:2988)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at com.android.blitz_v1_1.Foto.macheFoto(Foto.java:96)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at com.android.blitz_v1_1.Test1Activity.onClick(Test1Activity.java:281)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at android.view.View.performClick(View.java:2533)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at android.view.View$PerformClick.run(View.java:9320)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at android.os.Handler.handleCallback(Handler.java:587)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at android.os.Handler.dispatchMessage(Handler.java:92)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at android.os.Looper.loop(Looper.java:150)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at android.app.ActivityThread.main(ActivityThread.java:4385)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at java.lang.reflect.Method.invoke(Method.java:507)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
05-10 03:46:20.455: ERROR/AndroidRuntime(27933): at dalvik.system.NativeStart.main(Native Method)
[/WR]

[WR]
// Compiled from Activity.java (version 1.5 : 49.0, super bit)
public class android.app.Activity extends android.view.ContextThemeWrapper implements android.view.LayoutInflater$Factory, android.view.Window$Callback, android.view.KeyEvent$Callback, android.view.View$OnCreateContextMenuListener, android.content.ComponentCallbacks {

// Field descriptor #14 I
public static final int RESULT_CANCELED = 0;

// Field descriptor #14 I
public static final int RESULT_OK = -1;

// Field descriptor #14 I
public static final int RESULT_FIRST_USER = 1;

// Field descriptor #22 [I
protected static final int[] FOCUSED_STATE_SET;

// Field descriptor #14 I
public static final int DEFAULT_KEYS_DISABLE = 0;

// Field descriptor #14 I
public static final int DEFAULT_KEYS_DIALER = 1;

// Field descriptor #14 I
public static final int DEFAULT_KEYS_SHORTCUT = 2;

// Field descriptor #14 I
public static final int DEFAULT_KEYS_SEARCH_LOCAL = 3;

// Field descriptor #14 I
public static final int DEFAULT_KEYS_SEARCH_GLOBAL = 4;

// Method descriptor #32 ()V
// Stack: 3, Locals: 1
public Activity();
0 aload_0 [this]
1 invokespecial android.view.ContextThemeWrapper() [1]
4 new java.lang.RuntimeException [2]
7 dup
8 ldc <String "Stub!"> [3]
10 invokespecial java.lang.RuntimeException(java.lang.String) [4]
13 athrow
Line numbers:
[pc: 0, line: 6]
Local variable table:
[pc: 0, pc: 14] local: this index: 0 type: android.app.Activity

// Method descriptor #39 ()J
// Stack: 3, Locals: 0
public static long getInstanceCount();
0 new java.lang.RuntimeException [2]
3 dup
4 ldc <String "Stub!"> [3]
6 invokespecial java.lang.RuntimeException(java.lang.String) [4]
9 athrow
Line numbers:
[pc: 0, line: 7]

// Method descriptor #41 ()Landroid/content/Intent;
// Stack: 3, Locals: 1
public android.content.Intent getIntent();
0 new java.lang.RuntimeException [2]
3 dup
4 ldc <String "Stub!"> [3]
6 invokespecial java.lang.RuntimeException(java.lang.String) [4]
9 athrow
Line numbers:
[pc: 0, line: 8]
Local variable table:
[pc: 0, pc: 10] local: this index: 0 type: android.app.Activity

// Method descriptor #43 (Landroid/content/Intent;)V
// Stack: 3, Locals: 2
public void setIntent(android.content.Intent newIntent);
0 new java.lang.RuntimeException [2]
3 dup
4 ldc <String "Stub!"> [3]
6 invokespecial java.lang.RuntimeException(java.lang.String) [4]
9 athrow
Line numbers:
[pc: 0, line: 9]
Local variable table:
[pc: 0, pc: 10] local: this index: 0 type: android.app.Activity
[pc: 0, pc: 10] local: newIntent index: 1 type: android.content.Intent

// Method descriptor #47 ()Landroid/app/Application;
// Stack: 3, Locals: 1
public final android.app.Application getApplication();
0 new java.lang.RuntimeException [2]
3 dup
4 ldc <String "Stub!"> [3]
6 invokespecial java.lang.RuntimeException(java.lang.String) [4]
9 athrow
Line numbers:
[pc: 0, line: 10]
Local variable table:
[pc: 0, pc: 10] local: this index: 0 type: android.app.Activity

// Method descriptor #49 ()Z
// Stack: 3, Locals: 1
public final boolean isChild();
0 new java.lang.RuntimeException [2]
3 dup
4 ldc <String "Stub!"> [3]
6 invokespecial java.lang.RuntimeException(java.lang.String) [4]
9 athrow
Line numbers:
[pc: 0, line: 11]
Local variable table:
[pc: 0, pc: 10] local: this index: 0 type: android.app.Activity[/WR]




Passieren tut das ganze wenn ich eine Knopf drücke,
auszugsweise der Code: (es handelt sich im den Knopf beweisfoto...)

Java:
public void onClick(View v) {

public class Test1Activity extends Activity implements OnClickListener,
		LocationListener, OnItemSelectedListener {
...
	Foto foto = new Foto();
...
		if (v == buttonBeweisfoto) {
//			macheFoto();
			foto.macheFoto();
			logger.writeLog();
			// Intent intent = new Intent(this, Foto.class);
			// Intent intent = new Intent(Intent.ACTION_DIAL);
			// startActivity(intent);
		} else if (v == buttonSenden) {
			strKennzeichen = edittextKennzeichen.getText().toString();
			strKennzeichen = strKennzeichen.toUpperCase();
			checkboxMitGefaehrdung = (CheckBox) findViewById(R.id.checkboxMitGefaehrdung);
			edittextKennzeichen.setText(edittextKennzeichen.getText()
					.toString().toUpperCase());
			sendeMitteilung();
		} else if (v == jpgView) {
//			zeigeFoto();
			foto.zeigeFoto();
			// zeigeFoto();
		}
	}
}


Und dann noch die Klasse in die er dann springt:
Java:
package com.android.blitz_v1_1;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import com.android.blitz_v1_1.R;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.widget.Button;
import android.widget.Toast;

public class Foto extends Activity{
//	private Test1Activity hauptklasse;
//	public Foto(Test1Activity hauptklasse) {
//		this.hauptklasse = hauptklasse;
//	
//	
//	
//	}
	
	Foto(){
		
	}
	
	private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
	
	final File sdcard = Environment.getExternalStorageDirectory();
	final File fileFotoGespiegelt = new File(sdcard, File.separator
			+ "ps" + File.separator + "foto" + File.separator
			+ "foto_gespiegelt.jpg");
	final File fileFoto = new File(sdcard, File.separator + "ps"
			+ File.separator + "foto" + File.separator + "foto.jpg");
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.meldender);
		Intent intent = new Intent(Intent.ACTION_DIAL);
		startActivity(intent);
	}
	
		

	public void zeigeFoto() {
		try {
			File videoFile2Play = new File("/sdcard/ps/foto/foto.jpg");
			Intent i = new Intent();
			i.setAction(android.content.Intent.ACTION_VIEW);
			i.setDataAndType(Uri.fromFile(videoFile2Play), "image/jpg");
			startActivity(i);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
//			toast("Kein Bild vorhanden!");
		}

	}

	public void macheFoto() {
		// strJetztUhrzeit = strJetztUhrzeit.replaceAll("\\D", ""); // \D:

		// ersetze
		// alle
		// Nicht-Zahlen
		// durch
		// ""
		// :
		// in
		// Zeitangabe
		// läßt
		// sich
		// nicht
		// in
		// Dateinamen
		// übernehmen
		// [url=http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#sum]Pattern (Java 2 Platform SE v1.4.2)[/url]

		// strKennzeichen = edittextKennzeichen.getText().toString();
		// strKennzeichen = strKennzeichen.toUpperCase();

		loescheFoto(fileFotoGespiegelt);
		loescheFoto(fileFoto);
		Uri outputFileUri = Uri.fromFile(fileFotoGespiegelt);
		Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
		startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

		this.setResult(CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE, intent);
//		strFilename = "foto";
	}

	public void loescheFoto(File file) {
		if (file.exists()) {
			boolean deleted = file.delete();
		}
	}

	public void spiegelnBild(String foto) {
		Bitmap bitmap, bitmaprotated;
		int bmpWidth, bmpHeight;
		Matrix matrixMirror, matrixRotate;
		Matrix matrix1 = new Matrix();
		Matrix matrix2 = new Matrix();

		// bitmap = BitmapFactory.decodeFile(imageInSD);
		bitmap = BitmapFactory.decodeFile(fileFotoGespiegelt.toString());
		bmpWidth = bitmap.getWidth();
		bmpHeight = bitmap.getHeight();

		float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1 };
		matrixMirror = new Matrix();
		matrixRotate = new Matrix();

		matrixMirror.setValues(mirrorY);
		matrix1.postConcat(matrixMirror);

		Bitmap mirrorBitmap = Bitmap.createBitmap(bitmap, 0, 0, bmpWidth,
				bmpHeight, matrix1, true);

		matrix2.postRotate(180);
		matrix2.postConcat(matrixRotate);

		// matrix1.postRotate(180);
		bitmaprotated = Bitmap.createBitmap(mirrorBitmap, 0, 0,
				mirrorBitmap.getWidth(), mirrorBitmap.getHeight(), matrix2,
				true);

		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
		bitmaprotated.compress(Bitmap.CompressFormat.JPEG, 85, bytes);

		// you can create a new file name "test.jpg" in sdcard folder.
		File f = new File(fileFoto.toString());
		try {
			f.createNewFile();
			// write the bytes in file
			FileOutputStream fo = new FileOutputStream(f);
			fo.write(bytes.toByteArray());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// myImageView.setImageBitmap(mirrorBitmap);
	}

}

Es gibt einen Fehler beim Aufruf des startActivityOnResult, bzw. davor. Soweit bin ich durch googeln auch schon gekommen. Aber ich weiß nicht was ich machen muss, um den Fehler zu beheben....
Konkret angemeckert wird die Zeile 97..., aber ich instanziere doch ein Objekt?!? Warum nullPointerException?
Konkret ist es doch irgendwie die Kommunikation zwischen den Intents untereinander, oder?

Die neue Klasse ist in der manifest.xml bekannt...

Kann jemand helfen?
 
Zuletzt bearbeitet:

aquarium1974

Aktives Mitglied
Das interessante ist, daß beim Debuggen ab und zu diese NullPointerException kommt, und manchmal nicht. Wenn sie nicht kommt, dann kommt 'nur' die Source not Found-Meldung.

Habe mal testweise das Objekt der aufrufenden Klasse mit übergeben, leider immer noch der selbe Fehler.

Aber so muss es doch irgendwie gehen?

Java:
public class Test1Activity extends Activity implements OnClickListener,
		LocationListener, OnItemSelectedListener {
...

       Foto foto = new Foto(this);


...
}
 
Zuletzt bearbeitet:
M

MiDniGG

Gast
Also wenn ich mich nicht täusche kann es so nicht gehen.
Da die Klasse Foto ebenfalls eine Activity ist, kann Du nicht einfach eine Instanz davon erstellen und Methoden aufrufen. Wenn dann musst Du in Deiner Test1Activity die Foto-Activity mit startActivity aufrufen, dann sollte es dort auch weitergehen.
Ansonsten musst Du das ganze Foto-Zeug direkt in der Test1 machen.

Du könntest es dann, bspw. beim Klick auf buttonBeweisfoto, in etwa so machen:

Java:
Intent intent = new Intent(this, Foto.class);
intent.putExtra("TODO", 1);
startActivity(intent);

und in der onCreate von Foto dann in etwa:

Java:
int todo = getIntent().getExtras().get("TODO");
if(todo == 1) {
   zeigeFoto();
}
 

aquarium1974

Aktives Mitglied
Ansonsten musst Du das ganze Foto-Zeug direkt in der Test1 machen.


Ja und genau das will ich nicht.
Es ist ja derzeit so, daß es alles in einer riesen Quatschklasse ist. Ich will das so aufsplitten, daß jede Klasse eine Sammlung zusammengehöriger Methoden beinhaltet und nicht einen Mega-Brei.

Macht man doch so, oder?

Ich finds jedenfalls übersichtlicher, läuft halt nur noch nicht.
Aber wird schon!
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
Arif Android Android Studio: Fehler beim Einbinden fremder Bibliothek? Android & Cross-Platform Mobile Apps 2
JavaWolf165 Android Fehler beim Speichern/Downloaden einer Datei Android & Cross-Platform Mobile Apps 2
M Android Fehler beim Parsen. Android & Cross-Platform Mobile Apps 29
S Fehler beim Textdatei einlesen!? Android & Cross-Platform Mobile Apps 7
A Mehrere Fehler beim Compilieren Android & Cross-Platform Mobile Apps 4
G Fehler beim Import "Invalid project description" Android & Cross-Platform Mobile Apps 2
S Android Fehler beim Anzeigen meines Apps auf Galaxy Tab Android & Cross-Platform Mobile Apps 4
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
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
R Android Wie kann ich diesen Fehler beheben? Android & Cross-Platform Mobile Apps 10
S IF Anweisung zeigt Fehler trotz richtiger Eingabe? Android & Cross-Platform Mobile Apps 7
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
M Fehler ohne Sinn? java.lang.RuntimeException: Unable to start activity ComponentInfo Android & Cross-Platform Mobile Apps 11
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
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
R Android Löschfunktion beim Wischen Android & Cross-Platform Mobile Apps 10
W Rand ändern beim ImageView bei Picasso Android & Cross-Platform Mobile Apps 1
L App stürtzt ab beim öffnen Android & Cross-Platform Mobile Apps 1
S Android Probleme beim Verbinden mit einer HTTPS Seite Android & Cross-Platform Mobile Apps 4
V Android Fehlermeldung beim Öffnen von Eclipse nach Installation der Android Erweiterung Android & Cross-Platform Mobile Apps 4
M Error beim drücken der Zurück-Taste am Handy Android & Cross-Platform Mobile Apps 2
A Fehlermeldung beim ändern der ViewGroup. Android & Cross-Platform Mobile Apps 6
H Buttons färben sich mit, beim Hintergrund ändern Android & Cross-Platform Mobile Apps 3
G Problem beim Rendern von 3D-Objekt Android & Cross-Platform Mobile Apps 0
L Android OutOfMemory beim erneuten Starten der App Android & Cross-Platform Mobile Apps 2
N Android Retain Dialog verschwindet beim drehen Android & Cross-Platform Mobile Apps 4
B Android GameLoopThread stürzt beim 2ten start der App ab? Android & Cross-Platform Mobile Apps 4
K Nullpointer beim Löschen von Datenbankeintrag, je nachdem wo der Befehl steht Android & Cross-Platform Mobile Apps 5
S Java ME Exception beim Abspielen von Musik Android & Cross-Platform Mobile Apps 6
G unterschiedliches Verhalten beim Installieren des App auf dem Smartphone Android & Cross-Platform Mobile Apps 3
K Android schwarzer Bildschirm beim Rendern von Text und Dreiecken Android & Cross-Platform Mobile Apps 9
DaniSahne96 Problem beim Appdebuggen auf Smartphone Android & Cross-Platform Mobile Apps 3
P Android Problem beim Widget - Denkfehler ? Android & Cross-Platform Mobile Apps 2
J Android Verhalten beim Hinzufügen neuer Views? Android & Cross-Platform Mobile Apps 6
G Beziehung von THIS beim Imageadapter und AsyncTask Android & Cross-Platform Mobile Apps 7
V [Java] und [JavaME] ClientServer StreamConnection . Problem beim lesen / schreiben Android & Cross-Platform Mobile Apps 2
R Ein Problem beim ausführen von folgendem Quelltext Android & Cross-Platform Mobile Apps 11
N Error in HTTP operation beim KXML parsen Android & Cross-Platform Mobile Apps 7
A Problem beim Subtrahieren eines Double von einem Double Android & Cross-Platform Mobile Apps 5
G fehldermeldung beim klicken auf "build" Android & Cross-Platform Mobile Apps 8
L SecurityException beim lesen/schreiben eine Datei Android & Cross-Platform Mobile Apps 7
F Problem beim Erstellen der Jar File Android & Cross-Platform Mobile Apps 4
S createPlayer beim Entwickeln Android & Cross-Platform Mobile Apps 6
S Neue Activity lässt sich nicht starten Android & Cross-Platform Mobile Apps 28
M App Programmierung: Thread starten und Variablenwerte oder Objekte mitgeben Android & Cross-Platform Mobile Apps 2
H Android-App starten Android & Cross-Platform Mobile Apps 28
C Activity ohne Aktion starten Android & Cross-Platform Mobile Apps 8
T Android Starten der E-Mail-App Android & Cross-Platform Mobile Apps 6
tuttle64 J2ME SDK starten Android & Cross-Platform Mobile Apps 4
J Totaler JvaME Anfaenger - will Emulator starten. Android & Cross-Platform Mobile Apps 2

Ähnliche Java Themen

Neue Themen


Oben