Entwickelte App startet nicht richtig!!!

  • 13 Antworten
  • Letztes Antwortdatum
T

Techniker2013

Neues Mitglied
0
Hallo liebe Mitglieder,

Ich habe für ein Schulprojekt eine App entwickelt. Ich konnte diese bereits in einigen Test laufen lassen. ich habe lediglich den SourceCode einwenig gegliedert, damit es übersichtlicher ist und nun lässt sich die App nach dem installieren gar nicht mehr starten bzw. schließt sich nach öffnen sofort.

Woran kann so etwas liegen???

Techniker2013
 
Um dir dabei helfen zu können, solltest du deiner Frage schon den Sourcecode, oder zumindest eine genauere Fehlerbeschreibung beifügen. Das kann theoretisch alles sein.
Wenn du die App installieren kannst, dann scheint es ja schonmal keine Compilererrors zu geben.

Was zeigt der LogCat denn an?
 
package de.icarus;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import java.util.UUID;


import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

import android.util.Log;
import android.view.Gravity;

import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;

import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements SensorEventListener{
//Hochzeiten
ConnectToBluetooth connectBT;
//Globale Variablen
public BluetoothSocket scSocket;
public SendReceiveBytes sendReceiveBT=null;
public static final int MESSAGE_WRITE = 1;
public static final int MESSAGE_READ = 2;
private static final int REQUEST_ENABLE_BT = 0;
public String readMessage="";
public String action;
//Buttons und TextViews
Button AusButton;
Button GelbButton;
Button BlauButton;
TextView textView2;
TextView acceleration;

BluetoothAdapter bluetooth;
ArrayAdapter<String> mArrayAdapter;
BroadcastReceiver mReceiver;
IntentFilter filter;
BluetoothDevice device;
private SensorManager mySensorManager;
private Sensor accelerometer;
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_WRITE:
//Do something when writing
break;
case MESSAGE_READ:
//Get the bytes from the msg.obj
byte[] readBuf = (byte[]) msg.obj;
// construct a string from the valid bytes in the buffer
readMessage = new String(readBuf, 0, msg.arg1);
break;
}
}
};

//Arrays
public float values[];
byte[] myByte;


private byte[] charToBytesUTFCustom(char[] sendLetter) {
// TODO Auto-generated method stub
return null;
}

//**********************************************************************************************************
//----------------------------------------------------------------------------------------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
onActivityResult();
ToastMaster(action);
AccelerationAuslesen();
ButtonsAuslesen();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
//----------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------
private void AccelerationAuslesen() {
// TODO Auto-generated method stub
mySensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
accelerometer=mySensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mySensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);

acceleration=(TextView)findViewById(R.id.acceleration);
}
@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub

}
@Override
public void onSensorChanged(SensorEvent event) {
float result=event.values[0];
double X=(double)(result);
int XAchse=(int)(Math.round(X));

float result1=event.values[1];
double Y=(double)(result1);
int YAchse=(int)(Math.round(X));

acceleration.setText("X: " +XAchse + "/n Y: "+ YAchse);

}
//----------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------
private void onActivityResult() {
// TODO Auto-generated method stub
bluetooth= BluetoothAdapter.getDefaultAdapter();
if (bluetooth == null) {
// Device does not support Bluetooth
Toast.makeText(getApplicationContext(), "Bluetooth ist nicht eingeschaltet", Toast.LENGTH_LONG).show();
finish();
}
else{
if (!bluetooth.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
if (!bluetooth.isDiscovering()) {
bluetooth.startDiscovery();
}
}
}
}

//----------------------------------------------------------------------------------------------------------
/* This BroadcastReceiver will display discovered Bluetooth devices */
public class myOwnBroadcastReceiver extends BroadcastReceiver {
ConnectToBluetooth connectBT;

@Override
public void onReceive(Context context, Intent intent) {
String action=intent.getAction();
ToastMaster("ACTION:" + action);

//Notification that BluetoothDevice is FOUND
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
//Display the name of the discovered device
String discoveredDeviceName = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
ToastMaster("Discovered: " + discoveredDeviceName);

//Display more information about the discovered device
BluetoothDevice discoveredDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
ToastMaster("getAddress() = " + discoveredDevice.getAddress());
ToastMaster("getName() = " + discoveredDevice.getName());

int bondyState=discoveredDevice.getBondState();
ToastMaster("getBondState() = " + bondyState);

String mybondState;
switch(bondyState) {
case 10:
mybondState="BOND_NONE";
break;
case 11:
mybondState="BOND_BONDING";
break;
case 12:
mybondState="BOND_BONDED";
break;
default:
mybondState="INVALID BOND STATE";
break;
}
ToastMaster("getBondState() = " + mybondState);

//Change foundDevice to true which will make the screen turn green
boolean foundDevice = true;

//Connect to the discovered bluetooth device (SeeedBTSlave)
if (discoveredDeviceName.equals("SeeedBTSlave")) {
ToastMaster("Connecting you Now !!");
BroadcastReceiver myDiscoverer =new myOwnBroadcastReceiver();
unregisterReceiver(myDiscoverer);
connectBT = new ConnectToBluetooth(discoveredDevice);
//Connect to the the device in a new thread
new Thread(connectBT).start();
}
}

//Notification if bluetooth device is connected
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
ToastMaster("CONNECTED _ YAY");
int counter=0;

while (scSocket==null) {
//do nothing
}
ToastMaster("scSocket" + scSocket);
boolean BTisConnected = true; //turn screen purple
if (scSocket!=null) {
sendReceiveBT = new SendReceiveBytes(scSocket);
new Thread(sendReceiveBT).start();
sendReceiveBT.write(myByte);
}
}
}

public byte[] stringToBytesUTFCustom(String str) {
char[] buffer = str.toCharArray();
byte[] b = new byte[buffer.length << 1];
for (int i = 0; i < buffer.length; i++) {
int bpos = i << 1;
b[bpos] = (byte) ((buffer&0xFF00)>>8);
b[bpos + 1] = (byte) (buffer&0x00FF);
}
return b;
}

}

//----------------------------------------------------------------------------------------------------------
public class ConnectToBluetooth implements Runnable {
private BluetoothDevice btShield;
private BluetoothSocket mySocket = null;
private UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

public ConnectToBluetooth(BluetoothDevice bluetoothShield) {
btShield = bluetoothShield;
try {
mySocket = btShield.createRfcommSocketToServiceRecord(uuid);
}
catch(IOException createSocketException) {
//Problem with creating a socket
Log.e("ConnectToBluetooth", "Error with Socket");
}
}

@Override
public void run() {
/* Cancel discovery on Bluetooth Adapter to prevent slow connection */
bluetooth.cancelDiscovery();

try {
/*Connect to the bluetoothShield through the Socket. This will block
until it succeeds or throws an IOException */
mySocket.connect();
BluetoothSocket scSocket = mySocket;
}
catch (IOException connectException) {
Log.e("ConnectToBluetooth", "Error with Socket Connection");
try {
mySocket.close(); //try to close the socket
}
catch(IOException closeException) {
}
return;
}
}

// Will allow you to get the socket from this class
public BluetoothSocket getSocket() {
return mySocket;
}

/* Will cancel an in-progress connection, and close the socket */
public void cancel() {
try {
mySocket.close();
}
catch (IOException e) {
}
}
}
//----------------------------------------------------------------------------------------------------------
private class SendReceiveBytes implements Runnable {
private BluetoothSocket btSocket;
private InputStream btInputStream = null;
;
private OutputStream btOutputStream = null;
String TAG = "SendReceiveBytes";

public SendReceiveBytes(BluetoothSocket socket) {
btSocket = socket;
try {
btInputStream = btSocket.getInputStream();
btOutputStream = btSocket.getOutputStream();
}
catch (IOException streamError) {
Log.e(TAG, "Error when getting input or output Stream");
}
}

public void run() {
byte[] buffer = new byte[1024]; // buffer store for the stream
int bytes; // bytes returned from read()

// Keep listening to the InputStream until an exception occurs
while (true) {
try {
// Read from the InputStream
bytes = btInputStream.read(buffer);
// Send the obtained bytes to the UI activity
mHandler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
}
catch (IOException e) {
Log.e(TAG, "Error reading from btInputStream");
break;
}
}
}

/* Call this from the main activity to send data to the remote device */
public void write(byte[] bytes) {
try {
btOutputStream.write(bytes);
}
catch (IOException e) {
Log.e(TAG, "Error when writing to btOutputStream");
}
}

/* Call this from the main activity to shutdown the connection */
public void cancel() {
try {
btSocket.close();
}
catch (IOException e) {
Log.e(TAG, "Error when closing the btSocket");
}
}
}

//----------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------

/* My ToastMaster function to display a messageBox on the screen */
void ToastMaster(String textToDisplay) {
Toast myMessage = Toast.makeText(getApplicationContext(),
textToDisplay,
Toast.LENGTH_SHORT);
myMessage.setGravity(Gravity.CENTER, 0, 0);
myMessage.show();
}

//**************************************************************************************************
private void ButtonsAuslesen() {
// TODO Auto-generated method stub
AusButton=(Button)findViewById(R.id.AusButton);
GelbButton=(Button)findViewById(R.id.GelbButton);
BlauButton=(Button)findViewById(R.id.BlauButton);
final char sendLetter[] = {};

AusButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View event) {
// TODO Auto-generated method stub
sendLetter[0]='x';
}
});

GelbButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View event) {
// TODO Auto-generated method stub
sendLetter[1]='g';
}
});

AusButton.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View event) {
// TODO Auto-generated method stub
sendLetter[2]='b';
}
});

myByte = charToBytesUTFCustom(sendLetter);
sendReceiveBT.write(myByte);

}
}//eoc
 
niemand wird hier den source auf fehler überprüfen.wäre ein wenig sehr viel verlangt.

bitte schreib die fehlermeldung hier rein.


versuch mal ein project -> clean
 
Für Code solltest du immer das entsprechende Tag zum Formatieren benutzen. So ist das sehr anstrengend zu lesen.
 
Wenn ich die App starten will erscheint nur "App wurde beendet"
Ich habe vorher die Button onClick falsch programmiert und den Fehler behoben
Seit dem wenn ich es als apk installiere und öffne komm diese obengenannte Meldung.

Da ich noch relativ neu in der Android- und Javaprogrammierung, wie soll dies mit dem Project clean anstellen??
 
Post bitte mal die Fehlermeldung, die Eclipse im LogCat ausspuckt.
Den Clean kannst du über Project->Clean ausführen.
 
ein bisschen eigeninitiative ist meistens sehr sehr hilfreich.

wenn hier jemand ne fehlermeldung sehen will, dann frag doch google woher du eine android fehlermeldung bekommst => stichwort logcat.

wenn jemand einen tipp wie project -> clean gibt, und du damit nichts anfangen kannst, frag doch google ob es dir zeigt was das ist.


so schwer ist das nicht.



gerade anfänger fragen sind im web bereits tausendfach beantwortet.
 
Entschuldigung ich hab jetzt schnell schauen müssen was der Logcat ist :D

Im Logcat steht folgendes:

10-30 10:34:20.324: E/BluetoothAdapter(1862): Bluetooth binder is null
10-30
10:34:20.904: D/AndroidRuntime(1862): Shutting down VM
10-30
10:34:20.904: W/dalvikvm(1862): threadid=1: thread exiting with uncaught exception (group=0x41465700)
10-30
10:34:20.994: E/AndroidRuntime(1862): FATAL EXCEPTION: main
10-30
10:34:20.994: E/AndroidRuntime(1862): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.icarus/de.icarus.MainActivity}: java.lang.NullPointerException
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.os.Handler.dispatchMessage(Handler.java:99)
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.os.Looper.loop(Looper.java:137)
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-30
10:34:20.994: E/AndroidRuntime(1862): at java.lang.reflect.Method.invokeNative(Native Method)
10-30
10:34:20.994: E/AndroidRuntime(1862): at java.lang.reflect.Method.invoke(Method.java:525)
10-30
10:34:20.994: E/AndroidRuntime(1862): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-30
10:34:20.994: E/AndroidRuntime(1862): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-30
10:34:20.994: E/AndroidRuntime(1862): at dalvik.system.NativeStart.main(Native Method)
10-30 10:34:20.994: E/AndroidRuntime(1862): Caused by: java.lang.NullPointerException
10-30
10:34:20.994: E/AndroidRuntime(1862): at de.icarus.MainActivity.ButtonsAuslesen(MainActivity.java:406)
10-30
10:34:20.994: E/AndroidRuntime(1862): at de.icarus.MainActivity.onCreate(MainActivity.java:82)
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.app.Activity.performCreate(Activity.java:5133)
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-30
10:34:20.994: E/AndroidRuntime(1862): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-30
10:34:20.994: E/AndroidRuntime(1862): ... 11 more
10-30
10:34:41.175: I/Process(1862): Sending signal. PID: 1862 SIG: 9
 
Was steht in Zeile 406 von MainActivity?

Ist die Methode ButttonsAuslesen.
 
In der Zeile 406 steht nichts mehr, ich wollte übprünglich die Strings, die ich als byte senden wollte, in einem TextView anzeigenlassen, wenn ich einen Button drücke.
 
Kannst du bitte ein Screenshot von der Methode, also von den Zeilen rund um 406 posten?

Gesendet von meinem Galaxy Nexus mit der Android-Hilfe.de App
 
Ist leider eine Pdf geworde. Aber danke für die Hilfe.
 

Anhänge

  • Screen2.pdf
    130,9 KB · Aufrufe: 160
"SendLetter" ist null wenn du die APP startest.

Setzt die letzten beiden Zeilen der Methode in eine if-Abfrage, die prüft, ob sendLetter ungleich null ist.

Gesendet von meinem Galaxy Nexus mit der Android-Hilfe.de App
 

Ähnliche Themen

G
Antworten
0
Aufrufe
132
Gerdchen07
G
G
Antworten
1
Aufrufe
384
Gerdchen07
G
G
Antworten
13
Aufrufe
599
Gerdchen07
G
L
Antworten
2
Aufrufe
555
Lexub
L
migi01
Antworten
26
Aufrufe
1.991
migi01
migi01
Zurück
Oben Unten