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/IntentV
// 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...)
Und dann noch die Klasse in die er dann springt:
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?
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/IntentV
// 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: