我连接一个ıp凸轮(jpeg),并显示此图像,并且ı不断重复,过了一会儿,我的应用程序错误了。我测试了其他手机并展示了这款手机。
10-28 15:12:51.525: ERROR/AndroidRuntime(675): Uncaught handler: thread Thread-11 exiting due to uncaught exception
我的代码:
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) {
}
}
我的联系是:
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"));
}
}
...错误
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
答案 0 :(得分:2)
public void parse(InputStream is){
if(!mjpeghttp.isCanceled())
go();
go()
究竟做了什么?它调用connect()
,调用
if (!cancel) {
onReturn(res.getStatusLine().getStatusCode(), is);
}
onReturn()
再次致电parse()
。 parse()
拨打go()
来电connect()
来电onReturn()
来电parse()
来电......它永远不会(?)结束。为什么解析必须连接?每个函数调用都需要一点内存。经过大量调用后,没有剩余的内存,您将获得堆栈溢出异常。
你需要打破一些圈子。你可以删除它:
if(!mjpeghttp.isCanceled())
go();
我认为它甚至不会睡一次
try {
cancel = true;
System.out.println("Sleep sleep!");
Thread.sleep(60);
} catch (Exception ie) {
是否打印?
怎么样?
imageSet=false;
while(!imageSet)
{
if (connect())
if(parse())
imageSet=true;
}
答案 1 :(得分:2)
看起来好像你一遍又一遍地嵌套调用,直到堆栈溢出(这个站点非常合适的问题= P)。
我猜你想让连接方法实际返回一个值而不是调用onReturn方法。这会阻止你的递归嵌套,并且应该摆脱这个特殊的问题。
答案 2 :(得分:0)
我这样解决..再次感谢你... :)绝对我删除了
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);
}
}