# Mjpeg Code läuft unter Java jedoch nicht unter Android?



## holger27 (16. Aug 2011)

Hallo!

Ich möchte auf Android eine Mjpeg App programmieren welche es mir ermöglicht die Bilder eines MJPEG Streams auf meiner SD Karte abzuspeichern.

Ich habe mit hierfür im Netz einen Code gesucht und diesen so ummodelliert das er eigentlich Android Lauffähig ist, bzw. sich kompilieren lässt und normalerweise gehen sollte.

Das Problem ist nur das die App direkt nach dem Start abstürzt. Das komische ist dabei wenn ich das als normales Java Projekt lauffen lassen funktioniert das ganze perfekt! Von daher kann die "Code Logik" eigentlich nicht falsch sein...

Permissions für Internet und SD Karte habe ich beide eingetragen, daran kann es also auch nicht liegen. Ich habe mir den Code wirklich tausend mal angeschaut aber finde einfach keinen Fehler und im Android Debugger wird auch nichts angezeigt.

Es wäre wirklich toll wenn jemand mal über den Code drüberkucken könnte, vlt übersehe ich ja was ausschlaggebendes, aber wie gesagt unter java läuft der Code perfekt und sichert mir die Einzelbilder.

(Die Benutzer und Passwort Abfrage habe ich vorerst ausgeklammert, funktioniert bei diesem Stream auch ohne)

Klasse1:


```
package and.pro;

import java.awt.*;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.widget.Toast;

public class MjpegReaderActivity extends Activity {
	
	 public static String mjpgURL = "http://217.169.130.244/axis-cgi/mjpg/video.cgi?resolution=320x240";
	  String username = "";
	  String password = "";
	  static String base64authorization = null;
	  //private Image image = null;
	  private static boolean connected = false;
	  private boolean initCompleted = false;
	  static HttpURLConnection huc = null;
	  Runnable updater;

	  Integer frameNumber = 0;
	  
	  /**
	   * Used to calculate an average FPS
	   */
	  long[] frameTimes = new long[10];
	  static MJPEGParser parser;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        doIt();
    }
    
    public MjpegReaderActivity() {
        // only use authorization if all informations are available
        if (username != null && password != null) {
          //base64authorization = encodeUsernameAndPasswordInBase64(username, password);
          //MJPEGBean axPanel = new MJPEGBean();
         // new Thread(axPanel).start();
        }
      }
    
    public static void connect() {
        try {
          URL u = new URL(mjpgURL);
          huc = (HttpURLConnection) u.openConnection();

          // if authorization is required set up the connection with the encoded authorization-information
          //if (base64authorization != null) {
            //huc.setDoInput(true);
            //huc.setRequestProperty("Authorization", base64authorization);
            huc.connect();
          //}
          /*
           * This is the boundary string that my camera uses. I don't know if it is a standard or not, I kind of doubt
           * it...
           */
          String boundary = "--myboundary";
          String contentType = huc.getContentType();
          Pattern pattern = Pattern.compile("boundary=(.*)$");
          Matcher matcher = pattern.matcher(contentType);
          try {
            matcher.find();
            boundary = matcher.group(1);
          } catch (Exception e) {
          }

          InputStream is = huc.getInputStream();
          connected = true;
          parser = new MJPEGParser(is, boundary);
          //parser.addChangeListener(this);
        } catch (IOException e) { // incase no connection exists wait and try again, instead of printing the error
          try {
            huc.disconnect();
            Thread.sleep(60);
          } catch (InterruptedException ie) {
            huc.disconnect();
          }
          connect();
        } catch (Exception e) {
          ;
        }
      }

      public void disconnect() {
        try {
          if (connected) {
            parser.setCanceled(true);
            connected = false;
          }
        } catch (Exception e) {
          ;
        }
      }
      NumberFormat decFormat = DecimalFormat.getNumberInstance();

      
      public static void doIt()
      {
    		  connect();
    		    try {
    		        parser.parse();
    		      } catch (IOException e) {
    		        e.printStackTrace();
    		      }
      }

    }
```

Klasse2:


```
package and.pro;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class MJPEGParser {

		  private static final byte[] JPEG_START = new byte[]{(byte) 0xFF, (byte) 0xD8};
		  private static final int INITIAL_BUFFER_SIZE = 4096;
		  InputStream in;
		  byte[] boundary;
		  byte[] segment;
		  byte[] buf;
		  int cur, len;
		  boolean canceled = false;
		  static int frameCounter = 0;
		  /**
		   * Stores ChangeListeners listening for when there is a new segment to be processed
		   */
		  // protected EventListenerList listenerList = new EventListenerList();

		  public boolean isCanceled() {
		    return canceled;
		  }

		  public void setCanceled(boolean canceled) {
		    this.canceled = canceled;
		    if (canceled) {
		      try {
		        // TODO make this thread-safe
		        in.close();
		      } catch (IOException e) {
		      }
		    }
		  }

		  /**
		   * Creates a new MJPEG parser. Call parse() to begin parsing.
		   *
		   * @param in
		   *           An input stream to parse
		   * @param boundary
		   *           The boundary marker for this MJPEG stream.
		   */
		  public MJPEGParser(InputStream in, String boundary) {
		    this.in = in;
		    this.boundary = boundary.getBytes();
		    buf = new byte[INITIAL_BUFFER_SIZE];
		    cur = 0;
		    len = INITIAL_BUFFER_SIZE;
		  }

		  /**
		   * Reads from the MJPEG input stream, parsing it for JPEG segments. Every time a JPEG segment is found, all
		   * registered change listeners will be notifed. They can retrieve the latest segment via getSegment(). Note that this
		   * isn't thread-safe: change listeners should retrieve the segment in the same thread in which they are notified.
		   *
		   */
		  public void parse() throws IOException {
		    int b;
		    while ((b = in.read()) != -1 && !canceled) {
		      append(b);
		      if (checkBoundary()) {
		        // We found a boundary marker. Process the segment to find the JPEG image in it
		        processSegment();
		        // And clear out our internal buffer.
		        cur = 0;
		      }
		    }
		  }

		  /**
		   * Processes the current byte buffer. Ignores the last len(BOUNDARY) bytes in the buffer. Searches through the buffer
		   * for the start of a JPEG. If a JPEG is found, the bytes comprising the JPEG are copied into the
		   * <code>segment</code> field. If no JPEG is found, nothing is done.
		   *
		   */
		  protected void processSegment() {
		    // First, look through the new segment for the start of a JPEG
		    boolean found = false;
		    int i;
		    for (i = 0; i < cur - JPEG_START.length; i++) {
		      if (segmentsEqual(buf, i, JPEG_START, 0, JPEG_START.length)) {
		        found = true;
		        break;
		      }
		    }
		    if (found) {
		      int segLength = cur - boundary.length - i;
		      segment = new byte[segLength];
		      System.arraycopy(buf, i, segment, 0, segLength);
		      getLastImage();
		      //fireChange();
		    }
		  }

		  /**
		   * @return The last JPEG segment found in the MJPEG stream.
		   */
		  
		  public void getLastImage()
		  {
			  frameCounter++;
			  byte[] buffer;
			  buffer = getSegment();
			  createImage(buffer);
		  }
		  
		  public byte[] getSegment() {
		    return segment;
		  }
		  
			public static boolean createImage(byte[] datei)
			{
				FileOutputStream outStream;
				if(datei.length <= 0)
					return false;
				try {
					outStream = new FileOutputStream("/sdcard/bild" + frameCounter + ".jpeg");
					outStream.write(datei,0,datei.length);
					outStream.close();
				} catch (FileNotFoundException e) {
		                        e.printStackTrace();
					return false;
				} catch (IOException e) {
					e.printStackTrace();
					return false;
				}
				return true;
			}

		  /**
		   * Compares sections of two buffers to see if they are equal.
		   *
		   * @param b1
		   *           The first buffer.
		   * @param b1Start
		   *           The starting offset into the first buffer.
		   * @param b2
		   *           The second buffer.
		   * @param b2Start
		   *           The starting offset into the second buffer.
		   * @param len
		   *           The number of bytes to compare.
		   * @return <code>true</code> if the <code>len</code> consecutive bytes in <code>b1</code> starting at
		   *         <code>b1Start</code> are equal to the <code>len</code>consecutive bytes in <code>b2</code> starting
		   *         at <code>b2Start</code>, <code>false</code> otherwise.
		   */
		  protected boolean segmentsEqual(byte[] b1, int b1Start, byte[] b2, int b2Start, int len) {
		    if (b1Start < 0 || b2Start < 0 || b1Start + len > b1.length || b2Start + len > b2.length) {
		      return false;
		    } else {
		      for (int i = 0; i < len; i++) {
		        if (b1[b1Start + i] != b2[b2Start + i]) {
		          return false;
		        }
		      }
		      return true;
		    }
		  }

		  /**
		   * @return true if if the end of the buffer matches the boundary
		   */
		  protected boolean checkBoundary() {
		    return segmentsEqual(buf, cur - boundary.length, boundary, 0, boundary.length);
		  }

		  /**
		   * @return the length of the internal image buffer in bytes
		   */
		  public int getBufferSize() {
		    return len;
		  }

		  /**
		   * Appends the given byte into the internal buffer. If it won't fit, the buffer's size is doubled.
		   *
		   * @param i
		   *           the byte to append onto the internal byte buffer
		   */
		  protected void append(int i) {
		    if (cur >= len) {
		      // make buf bigger
		      byte[] newBuf = new byte[len * 2];
		      System.arraycopy(buf, 0, newBuf, 0, len);
		      buf = newBuf;
		      len = len * 2;
		    }
		    buf[cur++] = (byte) i;
		  }
		}
```


----------



## Bolle52 (16. Aug 2011)

poste bitte vorher den stacktrace. das wäre sehr viel hilfreicher, als wenn du nur den sourcecode postest.


----------



## Holger27 (16. Aug 2011)

Hi Bolle! Danke dir schonmal für deine schnelle Antwort! Wie kann ich mir den StackTrace den anzeigen lassen? Leider finde ich das debugging mit Android sehr verwirrend. Ich habe versucht das Tool "TraceView" aus dem Android SDK zu starten. Dieses zeigt mir allerdings nichts an bzw. wird gleich wieder beendet. Danke für deine Hilfe! =)


----------



## Bolle52 (16. Aug 2011)

du kannst dir mit logcat den stacktrace anzeigen lassen. anleitungen zu logcat findest du genug bei google


----------



## Holger27 (16. Aug 2011)

hey!

Also folgende Logcat Ausgabe bekomme ich von meinem Emulator:


```
I/ActivityThread(  123): Publishing provider sms: com.android.providers.telephon
y.SmsProvider
I/ActivityThread(  123): Publishing provider telephony: com.android.providers.te
lephony.TelephonyProvider
D/AndroidRuntime(  116): --- registering native functions ---
D/dalvikvm(  119): GC_FOR_MALLOC freed 1373 objects / 241144 bytes in 563ms
D/dalvikvm(  119): GC_FOR_MALLOC freed 390 objects / 393656 bytes in 306ms
D/ConnectivityService(   59): getMobileDataEnabled returning true
D/StatusBar(   59): DISABLE_EXPAND: yes
I/ActivityManager(   59): Start proc android.process.acore for content provider
com.android.providers.contacts/.CallLogProvider: pid=167 uid=10000 gids={3003, 1
015}
D/PhoneApp(  123): onCreate: mProximityWakeLock: null
W/ActivityManager(   59): Unable to start service Intent { act=com.android.ussd.
IExtendedNetworkService }: not found
D/dalvikvm(   59): GC_EXTERNAL_ALLOC freed 4161 objects / 243720 bytes in 396ms
D/PhoneApp(  123): Resetting audio state/mode: IDLE
I/ActivityThread(  167): Publishing provider com.android.social: com.android.pro
viders.contacts.SocialProvider
D/AlarmManagerService(   59): Kernel timezone updated to 0 minutes west of GMT
W/SystemClock(  123): Unable to set rtc to 1313528199: Invalid argument
I/ActivityManager(   59): Start proc com.android.alarmclock for broadcast com.an
droid.alarmclock/.AlarmInitReceiver: pid=174 uid=10009 gids={}
I/ActivityThread(  167): Publishing provider applications: com.android.providers
.applications.ApplicationsProvider
D/MobileDataStateTracker(   59): default Received state= DISCONNECTED, old= DISC
ONNECTED, reason= radioTurnedOff, apnTypeList= default
D/MobileDataStateTracker(   59): default Received state= DISCONNECTED, old= DISC
ONNECTED, reason= gprsDetached, apnTypeList= default
D/SystemClock(  123): Setting time of day to sec=1313528199
I/ActivityThread(  174): Publishing provider com.android.alarmclock: com.android
.alarmclock.AlarmProvider
I/ActivityThread(  167): Publishing provider contacts;com.android.contacts: com.
android.providers.contacts.ContactsProvider2
D/dalvikvm(  123): GC_FOR_MALLOC freed 3594 objects / 220040 bytes in 560ms
D/dalvikvm(   59): GREF has increased to 201
D/MobileDataStateTracker(   59): default Received state= DISCONNECTED, old= DISC
ONNECTED, reason= (unspecified), apnTypeList= default
I/ActivityManager(   59): Start proc com.android.defcontainer for service com.an
droid.defcontainer/.DefaultContainerService: pid=189 uid=10010 gids={1015, 2001}

D/MccTable(  123): updateMccMncConfiguration: mcc=310, mnc=260
D/MccTable(  123): locale set to en_us
D/MccTable(  123): WIFI_NUM_ALLOWED_CHANNELS set to 11
I/WifiService(   59): WifiService trying to setNumAllowed to 11 with persist set
 to true
I/ActivityManager(   59): Config changed: { scale=1.0 imsi=310/260 loc=en_US tou
ch=3 keys=2/1/2 nav=3/1 orien=1 layout=17 uiMode=17 seq=3}
I/UsageStats(   59): Unexpected resume of com.android.launcher while already res
umed in com.android.launcher
I/ActivityManager(   59): Start proc com.android.music for broadcast com.android
.music/.MediaAppWidgetProvider: pid=193 uid=10022 gids={3003, 1015}
D/dalvikvm(   33): GC_EXPLICIT freed 266 objects / 10048 bytes in 772ms
D/TelephonyProvider(  123): Setting numeric '310260' to be the current operator
D/MobileDataStateTracker(   59): default Received state= CONNECTING, old= DISCON
NECTED, reason= simLoaded, apnTypeList= *
D/NetworkStateTracker(   59): setDetailed state, old =IDLE and new state=CONNECT
ING
D/ConnectivityService(   59): ConnectivityChange for mobile: CONNECTING/CONNECTI
NG
D/MobileDataStateTracker(   59): replacing old mInterfaceName (null) with /dev/o
map_csmi_tty1 for hipri
D/MobileDataStateTracker(   59): replacing old mInterfaceName (null) with /dev/o
map_csmi_tty1 for supl
D/MobileDataStateTracker(   59): replacing old mInterfaceName (null) with /dev/o
map_csmi_tty1 for mms
D/MobileDataStateTracker(   59): default Received state= CONNECTED, old= CONNECT
ING, reason= simLoaded, apnTypeList= *
D/NetworkStateTracker(   59): setDetailed state, old =CONNECTING and new state=C
ONNECTED
D/ConnectivityService(   59): ConnectivityChange for mobile: CONNECTED/CONNECTED

V/NetworkStateTracker(   59): Setting TCP values: [4094,87380,110208,4096,16384,
110208] which comes from [net.tcp.buffersize.umts]
W/ActivityManager(   59): Activity idle timeout for HistoryRecord{45033af0 com.a
ndroid.launcher/com.android.launcher2.Launcher}
D/dalvikvm(   33): GC_EXPLICIT freed 40 objects / 1744 bytes in 616ms
D/ConnectivityService(   59): adding dns 10.0.2.3 for mobile
D/PowerManagerService(   59): bootCompleted
D/VoldCmdListener(   29): volume mount /mnt/sdcard
I/Vold    (   29): /dev/block/vold/179:0 being considered for volume sdcard
D/Vold    (   29): Volume sdcard state changing 1 (Idle-Unmounted) -> 3 (Checkin
g)
D/dalvikvm(   33): GC_EXPLICIT freed 2 objects / 48 bytes in 253ms
D/Tethering(   59): Tethering got CONNECTIVITY_ACTION
D/Tethering(   59): MasterInitialState.processMessage what=3
E/HierarchicalStateMachine(   59): TetherMaster - unhandledMessage: msg.what=3
I/StorageNotification(   59): Media {/mnt/sdcard} state changed from {unmounted}
 -> {checking}
I//system/bin/fsck_msdos(   29): ** /dev/block/vold/179:0
I//system/bin/fsck_msdos(   29): ** Phase 1 - Read and Compare FATs
I//system/bin/fsck_msdos(   29): Attempting to allocate 2044 KB for FAT
I/ActivityManager(   59): Start proc com.android.quicksearchbox for broadcast co
m.android.quicksearchbox/.SearchWidgetProvider: pid=207 uid=10012 gids={3003}
I/ActivityThread(  167): Publishing provider call_log: com.android.providers.con
tacts.CallLogProvider
I/ActivityThread(  167): Publishing provider user_dictionary: com.android.provid
ers.userdictionary.UserDictionaryProvider
D/dalvikvm(   59): GC_FOR_MALLOC freed 8752 objects / 460232 bytes in 451ms
I/SearchManagerService(   59): Building list of searchable activities
I/ActivityThread(  207): Publishing provider com.android.quicksearchbox.google:
com.android.quicksearchbox.google.GoogleSuggestionProvider
D/dalvikvm(  128): GC_EXTERNAL_ALLOC freed 3228 objects / 201888 bytes in 479ms
I/ActivityManager(   59): Start proc com.android.protips for broadcast com.andro
id.protips/.ProtipWidget: pid=215 uid=10007 gids={}
W/WindowManager(   59): App freeze timeout expired.
W/WindowManager(   59): Force clearing freeze: AppWindowToken{450367e8 token=His
toryRecord{45033af0 com.android.launcher/com.android.launcher2.Launcher}}
D/OtaStartupReceiver(  123): Not a CDMA phone, no need to process OTA
I/ActivityManager(   59): Start proc android.process.media for broadcast com.and
roid.providers.downloads/.DownloadReceiver: pid=222 uid=10002 gids={1015, 1006,
2001, 3003}
I/RecoverySystem(   59): No recovery log file
I/SurfaceFlinger(   59): Boot is finished (24909 ms)
I/ARMAssembler(   59): generated scanline__00000177:03515104_00000001_00000000 [
 73 ipp] (95 ins) at [0x386a90:0x386c0c] in 6013072 ns
I/ActivityThread(  222): Publishing provider drm: com.android.providers.drm.DrmP
rovider
I/ActivityThread(  222): Publishing provider media: com.android.providers.media.
MediaProvider
V/MediaProvider(  222): Attached volume: internal
I/ActivityThread(  222): Publishing provider downloads: com.android.providers.do
wnloads.DownloadProvider
I/ActivityManager(   59): Start proc com.android.mms for broadcast com.android.m
ms/.transaction.MmsSystemEventReceiver: pid=233 uid=10015 gids={3003, 1015}
I/ActivityThread(  233): Publishing provider com.android.mms.SuggestionsProvider
: com.android.mms.SuggestionsProvider
D/MediaScannerService(  222): start scanning volume internal
D/dalvikvm(   59): GC_EXPLICIT freed 6393 objects / 306664 bytes in 521ms
D/SntpClient(   59): request time failed: java.net.SocketException: Address fami
ly not supported by protocol
I/ActivityManager(   59): Start proc com.android.email for broadcast com.android
.email/com.android.exchange.BootReceiver: pid=251 uid=10030 gids={3003, 1015}
D/KeyguardViewMediator(   59): pokeWakelock(5000)
D/KeyguardViewMediator(   59): pokeWakelock(5000)
I/ARMAssembler(   59): generated scanline__00000177:03515104_00001001_00000000 [
 91 ipp] (114 ins) at [0x299448:0x299610] in 936872 ns
I/ActivityManager(   59): Displayed activity com.android.launcher/com.android.la
uncher2.Launcher: 19077 ms (total 19077 ms)
I/ActivityThread(  251): Publishing provider com.android.email.provider: com.and
roid.email.provider.EmailProvider
I/ActivityThread(  251): Publishing provider com.android.exchange.provider: com.
android.exchange.provider.ExchangeProvider
I/ActivityThread(  251): Publishing provider com.android.email.attachmentprovide
r: com.android.email.provider.AttachmentProvider
D/Exchange(  251): BootReceiver onReceive
D/EAS SyncManager(  251): !!! EAS SyncManager, onCreate
D/EAS SyncManager(  251): !!! EAS SyncManager, onStartCommand
D/EAS SyncManager(  251): !!! EAS SyncManager, stopping self
D/Eas Debug(  251): Logging:
D/EAS SyncManager(  251): !!! EAS SyncManager, onDestroy
D/dalvikvm(  189): GC_EXPLICIT freed 785 objects / 56072 bytes in 2473ms
D/dalvikvm(   59): GREF has increased to 301
D/PackageParser(   59): Scanning package: /data/app/vmdl71072.tmp
I//system/bin/fsck_msdos(   29): Attempting to allocate 2044 KB for FAT
I/ActivityManager(   59): Process com.android.settings (pid 133) has died.
I/ActivityManager(   59): Process android.process.acore (pid 167) has died.
D/MediaScanner(  222):  prescan time: 2154ms
D/MediaScanner(  222):     scan time: 34ms
D/MediaScanner(  222): postscan time: 1ms
D/MediaScanner(  222):    total time: 2189ms
D/MediaScannerService(  222): done scanning volume internal
I//system/bin/fsck_msdos(   29): ** Phase 2 - Check Cluster Chains
I//system/bin/fsck_msdos(   29): ** Phase 3 - Checking Directories
I//system/bin/fsck_msdos(   29): ** Phase 4 - Checking for Lost Files
I//system/bin/fsck_msdos(   29): Next free cluster in FSInfo block (4965) not fr
ee
I//system/bin/fsck_msdos(   29): FIXED
I//system/bin/fsck_msdos(   29): 357 files, 1035138 free (517569 clusters)
I/logwrapper(   29): /system/bin/fsck_msdos terminated by exit(0)
I/Vold    (   29): Filesystem check completed OK
I/Vold    (   29): Device /dev/block/vold/179:0, target /mnt/sdcard mounted @ /m
nt/secure/staging
D/Vold    (   29): Volume sdcard state changing 3 (Checking) -> 4 (Mounted)
I/PackageManager(   59): Updating external media status from unmounted to mounte
d
I/StorageNotification(   59): Media {/mnt/sdcard} state changed from {checking}
-> {mounted}
I/PackageManager(   59): Removing non-system package:and.pro
D/PackageManager(   59): Scanning package and.pro
I/PackageManager(   59): Package and.pro codePath changed from /data/app/and.pro
-1.apk to /data/app/and.pro-2.apk; Retaining data and using new
I/PackageManager(   59): /data/app/and.pro-2.apk changed; unpacking
D/installd(   35): DexInv: --- BEGIN '/data/app/and.pro-2.apk' ---
D/dalvikvm(  128): GC_EXTERNAL_ALLOC freed 2283 objects / 107984 bytes in 198ms
D/dalvikvm(  270): DexOpt: load 65ms, verify 40ms, opt 5ms
D/installd(   35): DexInv: --- END '/data/app/and.pro-2.apk' (success) ---
W/PackageManager(   59): Code path for pkg : and.pro changing from /data/app/and
.pro-1.apk to /data/app/and.pro-2.apk
W/PackageManager(   59): Resource path for pkg : and.pro changing from /data/app
/and.pro-1.apk to /data/app/and.pro-2.apk
D/PackageManager(   59):   Activities: and.pro.MjpegReaderActivity
I/installd(   35): move /data/dalvik-cache/data@app@and.pro-2.apk@classes.dex ->
 /data/dalvik-cache/data@app@and.pro-2.apk@classes.dex
D/PackageManager(   59): New package installed in /data/app/and.pro-2.apk
I/Launcher.Model(  128): not binding apps: no Launcher activity
D/dalvikvm(  128): GC_EXPLICIT freed 1217 objects / 62320 bytes in 80ms
D/VoldCmdListener(   29): asec list
I/PackageManager(   59): No secure containers on sdcard
W/PackageManager(   59): Unknown permission com.google.android.googleapps.permis
sion.GOOGLE_AUTH.mail in package com.android.contacts
W/PackageManager(   59): Unknown permission android.permission.ADD_SYSTEM_SERVIC
E in package com.android.phone
W/PackageManager(   59): Not granting permission android.permission.SEND_DOWNLOA
D_COMPLETED_INTENTS to package com.android.browser (protectionLevel=2 flags=0x1b
e45)
W/PackageManager(   59): Unknown permission com.google.android.gm.permission.WRI
TE_GMAIL in package com.android.settings
W/PackageManager(   59): Unknown permission com.google.android.gm.permission.REA
D_GMAIL in package com.android.settings
W/PackageManager(   59): Unknown permission com.google.android.googleapps.permis
sion.GOOGLE_AUTH in package com.android.settings
W/PackageManager(   59): Unknown permission com.google.android.googleapps.permis
sion.GOOGLE_AUTH in package com.android.providers.contacts
W/PackageManager(   59): Unknown permission com.google.android.googleapps.permis
sion.GOOGLE_AUTH.cp in package com.android.providers.contacts
W/PackageManager(   59): Unknown permission com.google.android.googleapps.permis
sion.ACCESS_GOOGLE_PASSWORD in package com.android.development
W/PackageManager(   59): Unknown permission com.google.android.googleapps.permis
sion.GOOGLE_AUTH in package com.android.development
W/PackageManager(   59): Unknown permission com.google.android.googleapps.permis
sion.GOOGLE_AUTH.ALL_SERVICES in package com.android.development
W/PackageManager(   59): Unknown permission com.google.android.googleapps.permis
sion.GOOGLE_AUTH.YouTubeUser in package com.android.development
D/dalvikvm(   59): GC_FOR_MALLOC freed 9950 objects / 566104 bytes in 162ms
I/ActivityManager(   59): Force stopping package and.pro uid=10036
I/ActivityManager(   59): Force stopping package and.pro uid=10036
D/MediaScannerService(  222): start scanning volume external
V/MediaProvider(  222): /mnt/sdcard volume ID: 303250183
I/ActivityManager(   59): Force stopping package and.pro uid=10036
D/AlarmManagerService(   59): Kernel timezone updated to 0 minutes west of GMT
D/dalvikvm(  128): GC_EXPLICIT freed 10108 objects / 492296 bytes in 78ms
W/SystemClock(  123): Unable to set rtc to 1313528221: Invalid argument
D/SystemClock(  123): Setting time of day to sec=1313528221
I/ActivityManager(   59): Start proc com.svox.pico for broadcast com.svox.pico/.
VoiceDataInstallerReceiver: pid=275 uid=10028 gids={}
W/RecognitionManagerService(   59): no available voice recognition services foun
d
I/ActivityThread(  275): Publishing provider com.svox.pico.providers.SettingsPro
vider: com.svox.pico.providers.SettingsProvider
D/dalvikvm(   59): GC_EXPLICIT freed 5549 objects / 320680 bytes in 105ms
I/installd(   35): unlink /data/dalvik-cache/data@app@and.pro-1.apk@classes.dex
D/AndroidRuntime(  116): Shutting down VM
D/jdwp    (  116): adbd disconnected
I/AndroidRuntime(  116): NOTE: attach of thread 'Binder Thread #3' failed
D/AndroidRuntime(  285):
D/AndroidRuntime(  285): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
D/AndroidRuntime(  285): CheckJNI is ON
D/AndroidRuntime(  285): --- registering native functions ---
I/ActivityManager(   59): Force stopping package and.pro uid=10036
I/ActivityManager(   59): Starting activity: Intent { act=android.intent.action.
MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=and.pro/.MjpegRea
derActivity }
I/ActivityManager(   59): Start proc and.pro for activity and.pro/.MjpegReaderAc
tivity: pid=291 uid=10036 gids={3003, 1015}
D/AndroidRuntime(  285): Shutting down VM
D/jdwp    (  285): adbd disconnected
I/AndroidRuntime(  285): NOTE: attach of thread 'Binder Thread #3' failed
I/ARMAssembler(   59): generated scanline__00000077:03545404_00000004_00000000 [
 47 ipp] (67 ins) at [0x382988:0x382a94] in 5977275 ns
W/ActivityThread(  291): Application and.pro is waiting for the debugger on port
 8100...
I/System.out(  291): Sending WAIT chunk
I/dalvikvm(  291): Debugger is active
I/System.out(  291): Debugger has connected
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/ARMAssembler(   59): generated scanline__00000077:03515104_00000000_00000000 [
 33 ipp] (47 ins) at [0x38dcd8:0x38dd94] in 838335 ns
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
V/MediaProvider(  222): Attached volume: external
D/dalvikvm(  251): GC_FOR_MALLOC freed 4218 objects / 265672 bytes in 86ms
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): waiting for debugger to settle...
I/System.out(  291): debugger has settled (1413)
D/dalvikvm(  222): GC_FOR_MALLOC freed 5631 objects / 301936 bytes in 90ms
D/Email   (  251): *** synchronizeMailboxGeneric ***
D/MediaScanner(  222):  prescan time: 382ms
D/MediaScanner(  222):     scan time: 3310ms
D/MediaScanner(  222): postscan time: 1ms
D/MediaScanner(  222):    total time: 3693ms
D/MediaScannerService(  222): done scanning volume external
D/Email   (  251): *** synchronizeMailboxGeneric ***
W/ActivityManager(   59): Launch timeout has expired, giving up wake lock!
W/ActivityManager(   59): Activity idle timeout for HistoryRecord{44edb560 and.p
ro/.MjpegReaderActivity}
D/SntpClient(   59): request time failed: java.net.SocketException: Address fami
ly not supported by protocol
```


----------



## TheDarkRose (16. Aug 2011)

Ich denke dein Activity braucht zu lange zum starten. Du rufst in der onCreate() Methode doIt() auf, welche wiederum connect() aufruft und insgesamt dauert das wahrscheinlich zu lange. connect() solltest du lieber in einem anderen Lifecycle aufrufen. Vorallem verstehe ich nicht warum im connect() wiederum connect() aufgerufen wird, und warum ist parser static?


----------



## Holger27 (17. Aug 2011)

Hey,

danke dir erstmal,

also ich habe nun den connect Aufruf direkt in die onCreate Methode reingepackt, dies hat allerdings zu keiner Veränderung geführt. Was meinst du mit "zu lange dauern" ? Gibt es bei Android hier irgendwelche Vorgaben/Bedingungen?

Der erneute Connect Aufruf findet ja nur statt wenn die Verbindung aus irgendeinem Grund nicht zustande kommen konnte, er versucht es quasi erneut wenn es nicht funktioniert hat mit der Verbindung.

Bin für weitere Hilfe wirklich dankbar! =)


----------



## TheDarkRose (17. Aug 2011)

Naja Logcat sagt bei dir ja folgendes:

```
W/ActivityManager(   59): Launch timeout has expired, giving up wake lock!
W/ActivityManager(   59): Activity idle timeout for HistoryRecord{44edb560 and.p
ro/.MjpegReaderActivity}
```
Ob der letzte Fehler auch deine Activity betrifft, kann ich jetzt nicht sagen.

Verlager mal den connect in die onStart() Methode


----------



## Holger27 (17. Aug 2011)

Danke, leider hatte auch das Umlagern des Aufrufs in die onStart() Methode keine Veränderung bewirkt. Irgendwie muss das doch gehen, ich verzweifel echt noch damit


----------



## Bolle52 (17. Aug 2011)

bei logcat steht folgender fehler: 
	
	
	
	





```
java.net.SocketException: Address fami
ly not supported by protocol
```

was genau die ursache ist, kann ich nicht sagen. 

folgende punkte solltest du pruefen: 
1. hat der emulator eine internetverbindung?
2. ist eine firewall aktiv, die die internetverbindung des emulators blockiert?
3. wie viele connections machst du mit deinem code auf? wenn es mehr als eine ist, kann das schon die ursache sein
4. hat die app auch rechte ins internet zu gehen?

ps.

der sourcecodestil ist in teilen grottig. wieso ist die connect methode statisch und die disconnect methode nicht?


----------



## Pommes9485 (20. Aug 2011)

Der Emulator hat doch NIE Internet verbindung, oder irre ich mich da ?


----------



## Bolle52 (20. Aug 2011)

Pommes9485 hat gesagt.:


> Der Emulator hat doch NIE Internet verbindung, oder irre ich mich da ?




jap du irrst dich. beim emulator kannst du die internetverbindung mit f8 an und ausschalten. vorausgesetzt der host-pc hat eine internetverbindung.


----------

