小编brn*_*nby的帖子

Android Base64编码和解码在单元测试中返回null

我正在尝试使用http://developer.android.com/reference/android/util/Base64.html类在Android中解码Base64编码的字符串.

encodeToString和decode方法都返回null,我不知道出了什么问题,这是我的解码代码:

// Should decode to "GRC"
String friendlyNameBase64Encoded = "R1JD";

// This returns null
byte[] friendlyNameByteArray = Base64.decode(friendlyNameBase64Encoded, Base64.DEFAULT);

// Fails with NullPointerException
String friendlyName = new String(friendlyNameByteArray, "UTF-8");
Run Code Online (Sandbox Code Playgroud)

我正在运行Android API 23.1.0

java junit android unit-testing android-testing

15
推荐指数
4
解决办法
6051
查看次数

Camera2 ImageReader冻结重复捕获请求

我正在尝试使用camera2 API从相机捕获图像数据.我主要使用的是从android Capture2RAW示例中获取的代码.在完全停止之前,只有少数图像通过(即调用onImageAvailable).我尝试使用不同大小的RAW_SENSOR和JPEG格式捕获相同的结果.我究竟做错了什么?

this.mImageReader = ImageReader.newInstance(width, height, ImageFormat.RAW_SENSOR, /*maxImages*/ 1);
Surface surface = this.mImageReader.getSurface();
final List<Surface> surfaces = Arrays.asList(surface);
this.mCamera.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
    // Callback methods here
}, null);
CaptureRequest.Builder captureRequestBuilder;
captureRequestBuilder = this.mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
captureRequestBuilder.addTarget(surface);
this.mCaptureRequest = captureRequestBuilder.build();
this.mCaptureSession.setRepeatingRequest(mCaptureRequest, null, null);
Run Code Online (Sandbox Code Playgroud)

android android-camera2

10
推荐指数
1
解决办法
4068
查看次数

在jdb中指定sourcepath,我做错了什么?

我有一个java项目,其中文件系统如下:我有3个目录:bin,srclib.

  • src包含我的*.java文件
  • bin包含我的*.class文件(使用src中的文件编译)
  • lib包含大多数src文件导入的一些*.jar文件

我正在学习如何使用jdb,但每次我尝试使用list命令时,它只是说无法找到源文件.我从bin目录中运行以下命令:

jdb -classpath ../lib/*:. -sourcepath ../src envelope.Envelope
Run Code Online (Sandbox Code Playgroud)

我的main方法包含在信封包中,它是信封包的一部分,我做错了什么?

java jdb

5
推荐指数
1
解决办法
3783
查看次数

在这种情况下,malloc做了什么?

这行C代码有什么作用?

      be_node *ret = malloc(sizeof(*ret));
Run Code Online (Sandbox Code Playgroud)

be_node的定义可以在这个文件中找到:http://funzix.git.sourceforge.net/git/gitweb.cgi?p = funzix/funzix; a = blob_plain; f = bencode/bencode.h; hb = HEAD

上面的代码行在此文件中找到:http://funzix.git.sourceforge.net/git/gitweb.cgi?p = funzix/funzix; a = blob_plain; f = bencode/bencode.c; hb = HEAD

我不明白sizeof(*ret)如果刚刚被宣布会返回什么?

c parsing

4
推荐指数
1
解决办法
362
查看次数

如何使用 GDI API 在 Windows 桌面上绘图?

可能的重复:
使用类似于检查的 GDI+(或 GDI)在屏幕上绘制

我正在尝试编写一个没有窗口的蛇游戏,但冻结了前景并将蛇画在它上面。当游戏结束时,前景应该解冻。

我写了一些测试代码,应该在前景上绘制一个正方形,但它似乎只是冻结桌面一秒钟,然后冻结前景中的窗口,直到我最小化、最大化、关闭它或带来另一个窗口进入前景,它不会绘制任何东西。在代码中,我尝试存储桌面的位图,以便我基本上可以将其重置为原始状态并在不同的位置绘制正方形。任何人都可以发现我的代码的问题吗?

//Handle to the desktop window
HWND hDesktopWindow = GetDesktopWindow();

//Lock the window to prevent other applications drawing on it
if(!LockWindowUpdate(hDesktopWindow)){
    return 1;
}

//Calling GetDC with argument NULL retrieves the desktop's DC
HDC hdcDesktop = GetDCEx(hDesktopWindow, NULL, DCX_CACHE | DCX_LOCKWINDOWUPDATE);

//Create a compatible DC to allow us to store a bitmap of the desktop
HDC hdcCompatible;
if((hdcCompatible = CreateCompatibleDC(hdcDesktop)) == NULL){
    return 1;
}

//Create a compatible bitmap with the same dimensions as the …
Run Code Online (Sandbox Code Playgroud)

c++ winapi gdi bitmap

4
推荐指数
2
解决办法
5208
查看次数

右箭头符号导致突然结束?

我正在尝试写一个bittorrent客户端.为了解析文件等,我需要将torrent文件读入内存.我注意到fread没有将整个文件读入我的缓冲区.经过进一步调查后,似乎只要在文件中遇到如下所示的符号,fread就会停止读取文件.在FILE*指针上调用feof函数会返回16,表示已到达文件末尾.无论符号放在何处,都会发生这种情况.有人可以解释为什么会发生这种情况以及任何可行的解决方案.

符号突出显示如下:

在此输入图像描述

以下是执行读取操作的代码:

char *read_file(const char *file, long long *len){
struct stat st;
char *ret = NULL;
FILE *fp;

//store the size/length of the file
if(stat(file, &st)){
    return ret;
}
*len = st.st_size;

//open a stream to the specified file
fp = fopen(file, "r");
if(!fp){
    return ret;
}

//allocate space in the buffer for the file
ret = (char*)malloc(*len);
if(!ret){
    return NULL;
}

//Break down the call to fread into smaller chunks
//to account for a known bug which causes …
Run Code Online (Sandbox Code Playgroud)

c msvcrt

3
推荐指数
1
解决办法
922
查看次数

SDL:全屏半透明背景

我正在尝试编写一个具有覆盖整个屏幕的半透明背景的程序。经过一些研究,似乎 SDL 将是可行的方法。

我已经编写了代码来创建一个全屏窗口,其背景的 alpha 等于 100(255 中的 100),但由于某种原因,它只是绘制纯色。我做错了什么?

// Initialise SDL
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        this->throwSDLError("SDL_Init Error");
}

// Create the window and renderer
if (SDL_CreateWindowAndRenderer(0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP, &(this->window), &(this->renderer)) != 0) {
        this->throwSDLError("Could not create the window and renderer");
}

// Set the blend mode to specify how the alpha channel is used
if (SDL_SetRenderDrawBlendMode(this->renderer, SDL_BLENDMODE_BLEND) != 0) {
        this->throwSDLError("Could not set render draw blend mode");
}

// Set the colour to draw
if (SDL_SetRenderDrawColor(this->renderer, 200, 200, …
Run Code Online (Sandbox Code Playgroud)

c++ transparency sdl

3
推荐指数
1
解决办法
3092
查看次数

Dagger不喜欢抛出异常的构造函数

我正在尝试在我的Android应用程序中使用Dagger来简化依赖注入.看起来Dagger 2.0不支持抛出异常的构造函数.这个问题有方法解决吗?

重构和创建抛出异常的init方法似乎不可行,因为必须在整个依赖对象链上调用init重新引入了匕首解决的问题.

java android dagger dagger-2

3
推荐指数
1
解决办法
2177
查看次数

C++ HTTP GET请求问题?

我编写了一个程序,它将tcp请求发送到命令行中指定的Web地址并打印响应.当我将此请求发送到www.google.co.uk(或任何网站)时,我得不到任何回复:(

有人可以告诉我我做错了什么,以及谷歌的正确GET请求应该是什么样子.这是代码......

#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>

#pragma comment(lib, "Ws2_32.lib")

int main(int argc, char *argv[]){

WSADATA wsaData;
int iResult;

//Initialize Winsock
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if(iResult != 0){
    printf("WSAStartup failed: %d\n", iResult);
    return 1;
}

struct addrinfo *result = NULL,
                *ptr = NULL,
                hints;

ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;

#define DEFAULT_PORT "80"

//Resolve the server address and port
iResult = getaddrinfo(argv[1], DEFAULT_PORT, &hints, &result);
if(iResult != 0){
    printf("getaddrinfo failed: %d\n", iResult);
    WSACleanup();
    return …
Run Code Online (Sandbox Code Playgroud)

c++ tcp http winsock get-request

2
推荐指数
1
解决办法
5518
查看次数

如何使用malloc正确引用结构内的双指针

我编写了一个解析url并将其拆分为组件的函数.为了存储URL的组件,我将指针(到函数)传递给以下称为urlinfo的结构:

typedef struct urlstruct {
    char** protocol;
    char** address;
    char** port;
    char** page;
} urlstruct;
Run Code Online (Sandbox Code Playgroud)

包含双指针的原因是因为我不知道URL的每个组件有多长.在函数内部,我计算出存储每个组件所需的大小,并尝试使用以下行将内存分配给urlstruct的组件:

*(urlinfo->protocol) = (char*)malloc(i * sizeof(char));
Run Code Online (Sandbox Code Playgroud)

哪里(i * sizeof(char))是所需的尺寸.此行会导致访问冲突.有谁知道如何正确分配内存?

提前致谢 :)

c++ malloc struct pointers

1
推荐指数
1
解决办法
585
查看次数

将std :: string的一部分复制到另一个未初始化的字符串

我正在尝试编写一个C++函数,将std::string包含URL的URL拆分为其组件.我需要将组件复制到这个结构中:

typedef struct urlstruct {
    string protocol;
    string address;
    string port;
    string page;
} urlstruct;
Run Code Online (Sandbox Code Playgroud)

这是迄今为止的功能:

int parseAnnounce2(string announce, urlstruct *urlinfo){
    int i;

    if(announce.find("://") != string::npos){
        // "://" found in string, store protocol
        for(i = 0; i < announce.find("://"); i++){

        }
    } else {
        // No "://" found in string
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我需要将'://'序列之前的字符复制到urlinfo->协议字符串中.这样做的好方法是什么?

我知道我无法使用以下代码行分配它,因为协议字符串尚未初始化为包含该内存.

urlinfo->protocol[i] = announce[i];
Run Code Online (Sandbox Code Playgroud)

c++ string

1
推荐指数
1
解决办法
1838
查看次数

你如何生成一个随机的12位数字?

我正在用C++编写一个Bittorrent客户端,需要生成一个20字节的对等ID.前8个字符由-WW1000-表示客户端名称和版本号组成.其他12位数字需要是每次客户端启动时需要随机生成的随机数.

我怎么能生成12位数的随机数并将其与std::string包含前8个字符(-WW1000-)的连接?

c++ random

1
推荐指数
1
解决办法
3707
查看次数