如何处理这个错误而来自Android图库中选择图片? [英] How to handle this error while select image from android gallery?
问题描述
我有一个活动名称DrawingActivity Android图库中挑选图片的按钮。还有另一个活动的名称为DrawingSurface。在DrawingSurface活动我使用线程绘制的画布和处理。
I have button of pick image from android gallery in one activity name DrawingActivity. and there is another activity name as DrawingSurface. In DrawingSurface activity i am using thread to draw the canvas and handle it.
现在,当我从画廊去拾取图像我得到的错误是这样的:
Now while i am going to pickup the Image from gallery i got error like this:
11-04 12:12:50.226: ERROR/AndroidRuntime(518): FATAL EXCEPTION: main
11-04 12:12:50.226: ERROR/AndroidRuntime(518): java.lang.IllegalThreadStateException: Thread already started.
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at java.lang.Thread.start(Thread.java:1322)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at com.example.drawing.DrawingSurface.surfaceCreated(DrawingSurface.java:106)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.view.SurfaceView.updateWindow(SurfaceView.java:532)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:206)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.view.View.dispatchWindowVisibilityChanged(View.java:3891)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:719)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:719)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:719)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:719)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.view.ViewRoot.performTraversals(ViewRoot.java:744)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.os.Handler.dispatchMessage(Handler.java:99)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.os.Looper.loop(Looper.java:123)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at java.lang.reflect.Method.invokeNative(Native Method)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at java.lang.reflect.Method.invoke(Method.java:521)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-04 12:12:50.226: ERROR/AndroidRuntime(518): at dalvik.system.NativeStart.main(Native Method)
=====
在这里我得到了DrawingSurface活动这一错误的行是如下:
The Line where i got this error on DrawingSurface activity is as below:
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
thread.setRunning(true);
thread.start(); // error at this line
}
我用这code挑pssed按钮$ P $图片:
I am using this code to pick image on button pressed:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);//
//startActivity(intent);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),10);
//finish();
所以现在可以anybudy告诉我怎样可以处理这个问题?
So Now can anybudy tell me how i can handle this error ?
感谢。
推荐答案
您应该使用 thread.isAlive()
启动线程之前。
You should use thread.isAlive()
before starting the Thread .
这篇关于如何处理这个错误而来自Android图库中选择图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!