在一个线程里new一个dialog所出现的错误


04-01 14:17:22.499: WARN/dalvikvm(5119): threadid=17: thread exiting with uncaught exception (group=0x2aac9a08)
04-01 14:17:22.499: ERROR/AndroidRuntime(5119): Uncaught handler: thread Thread-9 exiting due to uncaught exception
04-01 14:17:22.499: INFO/global(5119): Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
04-01 14:17:22.519: INFO/global(5119): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
04-01 14:17:22.519: WARN/System.err(5119): java.io.FileNotFoundException: /data/logcat_1.txt
04-01 14:17:22.519: INFO/global(5119): Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
04-01 14:17:22.549: INFO/global(5119): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
04-01 14:17:22.619: WARN/System.err(5119): java.io.FileNotFoundException: /data/logcat_1.txt
04-01 14:17:22.619: ERROR/AndroidRuntime(5119): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
04-01 14:17:22.619: ERROR/AndroidRuntime(5119):     at android.os.Handler.<init>(Handler.java:121)
04-01 14:17:22.619: ERROR/AndroidRuntime(5119):     at android.app.Dialog.<init>(Dialog.java:104)
04-01 14:17:22.619: ERROR/AndroidRuntime(5119):     at android.app.AlertDialog.<init>(AlertDialog.java:63)
04-01 14:17:22.619: ERROR/AndroidRuntime(5119):     at android.app.AlertDialog.<init>(AlertDialog.java:59)
04-01 14:17:22.619: ERROR/AndroidRuntime(5119):     at android.app.AlertDialog$Builder.create(AlertDialog.java:786)
04-01 14:17:22.619: ERROR/AndroidRuntime(5119):     at android.app.AlertDialog$Builder.show(AlertDialog.java:801)
04-01 14:17:22.619: ERROR/AndroidRuntime(5119):     at com.**.**.**$2.run(UPhoneMark.java:62)

 

 

解决方法:在线程外创建一个公共的dialog,添加Context参数和所要显示的信息进行调用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
你可以使用佳能EDSDK提供的Live View功能,将实时图像以流的形式传输到你的应用程序中,然后在Dialog窗体中显示它。以下是一个简单的示例: 1. 首先,你需要在Dialog窗体中添加一个控件来显示图像。你可以使用MFC库提供的CStatic类或者其他控件,如PictureBox。 2. 在Dialog窗体的OnInitDialog()函数中初始化EDSDK,并启动Live View功能。以下是一些示例代码: ```cpp // 初始化EDSDK EdsInitializeSDK(); // 获取第一个连接的相机 EdsCameraListRef cameraList = NULL; EdsGetCameraList(&cameraList); EdsCameraRef camera = NULL; EdsGetChildAtIndex(cameraList, 0, &camera); // 打开相机 EdsOpenSession(camera); // 启动Live View EdsUInt32 device = 0; EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device); device |= kEdsEvfOutputDevice_PC; EdsSetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0, sizeof(device), &device); // 注册回调函数 EdsSetObjectEventHandler(camera, kEdsObjectEvent_All, handleObjectEvent, NULL); EdsSetPropertyEventHandler(camera, kEdsPropertyEvent_All, handlePropertyEvent, NULL); EdsSetCameraStateEventHandler(camera, kEdsStateEvent_All, handleStateEvent, NULL); ``` 3. 在回调函数中获取Live View图像,并将其显示在控件中。以下是一些示例代码: ```cpp void handlePropertyEvent(EdsPropertyEvent event, EdsPropertyID propertyId, EdsUInt32 parameter, EdsVoid* context) { // 获取Live View图像 EdsEvfImageRef image = NULL; EdsGetPropertyData(camera, kEdsPropID_Evf_ImageRef, 0, sizeof(image), &image); // 获取图像数据 EdsUInt32 dataSize = 0; EdsGetLength(image, &dataSize); unsigned char* data = new unsigned char[dataSize]; EdsGetPointer(image, (EdsVoid**)&data); // 在控件中显示图像 CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_IMAGE); CRect rect; pStatic->GetClientRect(&rect); CDC* pDC = pStatic->GetDC(); CImage img; img.Create(rect.Width(), rect.Height(), 24); for (int y = 0; y < rect.Height(); y++) { for (int x = 0; x < rect.Width(); x++) { int index = (y * rect.Width() + x) * 3; img.SetPixel(x, y, RGB(data[index + 2], data[index + 1], data[index])); } } img.BitBlt(pDC->m_hDC, 0, 0); pStatic->ReleaseDC(pDC); // 释放图像数据 delete[] data; EdsRelease(image); } ``` 注意,这只是一个简单的示例,你需要根据自己的需求进行修改和调整。同时,你也需要在Dialog窗体销毁时关闭相机和释放EDSDK资源。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值