views:

60

answers:

3

I connect a ıp cam(jpeg), and show this image, and ı repeat continually, After a while my app error this. And I tested other phone and showed this one.

10-28 15:12:51.525: ERROR/AndroidRuntime(675): Uncaught handler: thread Thread-11 exiting due to uncaught exception

my codes:

public void parse(InputStream is){
  try {
   if (!type.isMjpegStream()) {
    CameraManagerScreen.ActiveCam.setConnected(true);
    setImage(is);
    is.close();
    System.gc();
    if(!mjpeghttp.isCanceled())
      go();
   } 
  } catch (Exception e) {
  }
 }

and my connection is:

protected void connect() {
 InputStream is = null;

try {



 HttpParams httpParameters = new BasicHttpParams();
 // Set the timeout in milliseconds until a connection is
 // established.
 int timeoutConnection = 20000;
 HttpConnectionParams.setConnectionTimeout(httpParameters,
   timeoutConnection);
 // Set the default socket timeout (SO_TIMEOUT)
 // in milliseconds which is the timeout for waiting for data.
 int timeoutSocket = 20000;
 HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

 client = new DefaultHttpClient(httpParameters);

 method = new HttpGet(getUrl());
 System.out.println("Baglanıyor:  " + method.getURI().toString());
 method.addHeader("Authorization", getBase64Encode());

 res = client.execute(method);
 System.out.println("RESPONSE: "
   + res.getStatusLine().getStatusCode());

 is = res.getEntity().getContent();

 if (!cancel) {
  onReturn(res.getStatusLine().getStatusCode(), is);

 }

} catch (Exception e) {
 System.out.println(e.getMessage());

 try {

  cancel = true;

  Thread.sleep(60);

 } catch (Exception ie) {
}
 onError(new Exception("0"));
}
}

Error...

 10-28 14:13:06.794: INFO/dalvikvm(3502): Stack overflow, expanding (0x439b0200 to 0x439b0000)
10-28 14:13:06.794: INFO/dalvikvm(3502): Shrank stack (to 0x439b0200, curFrame is 0x439b0268)
10-28 14:13:06.794: WARN/dalvikvm(3502): threadid=17: thread exiting with uncaught exception (group=0x4001b180)
10-28 14:06:19.944: ERROR/AndroidRuntime(3420): Uncaught handler: thread Thread-11 exiting due to uncaught exception
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420): java.lang.StackOverflowError
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at java.util.Hashtable.get(Hashtable.java:274)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at java.util.Properties.getProperty(Properties.java:177)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at java.lang.System.getProperty(System.java:440)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at java.lang.System.getProperty(System.java:412)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at java.lang.Boolean.getBoolean(Boolean.java:174)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.harmony.luni.net.NetUtil$Action.run(NetUtil.java:89)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.harmony.luni.net.NetUtil$Action.run(NetUtil.java:80)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at java.security.AccessController.doPrivilegedImpl(AccessController.java:264)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at java.security.AccessController.doPrivileged(AccessController.java:84)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.harmony.luni.net.NetUtil.preferIPv4Stack(NetUtil.java:61)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:266)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at java.net.Socket.checkClosedAndCreate(Socket.java:889)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at java.net.Socket.connect(Socket.java:1036)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:140)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.connect(Http.java:75)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.connect(MjpegHttp.java:33)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.go(Http.java:46)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.CameraHttp.go(CameraHttp.java:13)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.go(Camera.java:121)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.parse(Camera.java:170)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.onReturn(MjpegHttp.java:23)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.connect(Http.java:82)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.connect(MjpegHttp.java:33)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.go(Http.java:46)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.CameraHttp.go(CameraHttp.java:13)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.go(Camera.java:121)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.parse(Camera.java:170)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.onReturn(MjpegHttp.java:23)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.connect(Http.java:82)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.connect(MjpegHttp.java:33)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.go(Http.java:46)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.CameraHttp.go(CameraHttp.java:13)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.go(Camera.java:121)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.parse(Camera.java:170)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.onReturn(MjpegHttp.java:23)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.connect(Http.java:82)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.connect(MjpegHttp.java:33)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.go(Http.java:46)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.CameraHttp.go(CameraHttp.java:13)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.go(Camera.java:121)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.parse(Camera.java:170)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.onReturn(MjpegHttp.java:23)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.connect(Http.java:82)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.connect(MjpegHttp.java:33)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.go(Http.java:46)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.CameraHttp.go(CameraHttp.java:13)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.go(Camera.java:121)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.parse(Camera.java:170)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.onReturn(MjpegHttp.java:23)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.connect(Http.java:82)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.MjpegHttp.connect(MjpegHttp.java:33)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.Http.go(Http.java:46)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.connection.CameraHttp.go(CameraHttp.java:13)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepvizyon.camera.Camera.go(Camera.java:121)
    10-28 14:06:19.994: ERROR/AndroidRuntime(3420):     at spexco.cepviz
+2  A: 
public void parse(InputStream is){
    if(!mjpeghttp.isCanceled())
      go();

What exactly does go() do? It calls connect(), what calls

if (!cancel) {
  onReturn(res.getStatusLine().getStatusCode(), is);
 }

And onReturn() calls parse() again. parse() calls go() calls connect() calls onReturn() calls parse() calls... It never(?) ends. Why does parsing have to connect? Every function call needs a bit of memory. After a lot of call, there is no more memory left and you get a Stack overflow exception.

You need to break the circle some where. You could remove this:

if(!mjpeghttp.isCanceled())
  go();

I don't think it even sleeps once

try {

  cancel = true;
  System.out.println("Sleep sleep!");
  Thread.sleep(60);

 } catch (Exception ie) {

Does it print at all?


How about?

imageSet=false;
while(!imageSet)
{
   if (connect())
     if(parse())
       imageSet=true;
}
Ishtar
parsing have to connect again, because connect brings jpeg image, parse sets image. On the other hand, my handler sets this image to screen. Always a picture shoulds be coming...
atasoyh
+2  A: 

It looks as though you keep nesting calls over and over until the stack overflows (very appropriate problem for this site =P).

I'm guessing that you want to actually have the connection methods return a value instead of calling an onReturn method. That would prevent your recursive nesting and should get rid of this particular problem.

Marc
thank you. But why did you think " very appropriate problem for this site =P)."
atasoyh
Because the site is called stackoverflow, and the error you're getting is 'stackoverflow'...
Mark Ingram
A: 

I solve like this.. Thank you again...:) Absolutely I remove if(!mjpeghttp.isCanceled()) go();

// start connection to ip-camera
public void go() {

    if (mjpeghttp == null) {
        mjpeghttp = new MjpegHttp();
        mjpeghttp.start();

    }
    if (type.isMjpegStream()) {
        mjpeghttp.go(this);
    } else {
        while (mjpeghttp.isCanceled()==false)
            mjpeghttp.go(this);
    }

}
atasoyh