我正在使用getApplicationContext()函数创建一个对话框,这会导致程序在调用dialog.show()时崩溃.我正在使用getApplicationContext(),因为我试图在Camera.PictureCallback()中打开对话框,如下所示:
Camera.PictureCallback pictureCallbackJpeg = new Camera.PictureCallback()
{
public void onPictureTaken(byte[] data, Camera c)
{
Context context = getApplicationContext();
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.send_dialog);
dialog.setTitle("Send image?");
dialog.show();
camera.startPreview();
}
};
Run Code Online (Sandbox Code Playgroud)
这是崩溃日志:
Thread [<1> main] (Suspended (exception WindowManager$BadTokenException))
Dialog.show() line: 245
myApp$1.onPictureTaken(byte[], Camera) line: 31
Camera$EventHandler.handleMessage(Message) line: 328
Camera$EventHandler(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 143
ActivityThread.main(String[]) line: 4914
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 868
ZygoteInit.main(String[]) line: 626
NativeStart.main(String[]) line: …Run Code Online (Sandbox Code Playgroud) 有没有人知道C++的字典API,它允许我搜索一个单词并取回定义?
(我不介意它是否是在线API,我必须使用JSON或XML来解析它)
编辑:对不起,我的意思是字词定义中的字典.不是C++地图.抱歉混淆.
我想知道是否可以从lua脚本发送电子邮件.我正在使用linux,所以我有mail命令,但我无法弄清楚如何使用它.
任何帮助将非常感激.
我对C编程很新,过去只使用C++和String类,但我想知道如何用另一个字符串来递归替换字符串.
我的代码是这样的,但它似乎没有正常工作,我无法确定它失败的地方.它在一次更换时工作正常,但不止一次,它失败了.
#include <stdio.h>
#include <string.h>
char *replace_str(char *str, char *orig, char *rep)
{
int current_index = 0;
static char buffer[10000];
if (!strstr(str, orig)) // Is 'orig' even in 'str'?
{
return str;
}
while (1)
{
char *p;
if (!(p = strstr(str + current_index, orig))) // Is 'orig' even in 'str'?
{
return buffer;
}
strncpy(buffer, str, p-str); // Copy characters from 'str' start to 'orig' st$
buffer[p-str] = '\0';
sprintf(buffer+(p-str), "%s%s", rep, p+strlen(orig));
printf("%d -> %s\n", current_index, buffer); …Run Code Online (Sandbox Code Playgroud) 我想检查一个脚本是否在python脚本中以特定的命令行参数运行。
例如,我想检查是否:
main.py testarg
Run Code Online (Sandbox Code Playgroud)
在跑。有什么办法可以实现?
提前致谢