문제

I've just installed the NDK onto Eclipse, but I'm having some trouble with something..

Here's the code:

#include <jni.h>
#include <stdlib.h>
#include <stdio.h>

void deleteFile(const char *fileName) {
    remove(fileName);
}

void writeFile(const char *fileName, byte array) {

}

But something is going wrong.. I got this error:

jni/[projectName].cpp:9:38: error: 'byte' has not been declared

byte couldn't be resolved! which is a big problem because I absolutely need that type.. I have to use it to write data into a file!

I've followed a lot of tutorials, I also tried to import all of my MinGW libraries with no success.

도움이 되었습니까?

해결책

byte isn't a standard C or C++ type ... It may be a typedef in a non-standard header file. Where have you seen code with that type ? May be you would like to use const unsigned char * ?

I know that Visual Studio define BYTE type:

typedef unsigned char BYTE;   // 8-bit unsigned entity.
typedef BYTE *        PBYTE;  // Pointer to BYTE.

But this is not standard. And it is "BYTE", not "byte".

다른 팁

'byte' doesn't exist in standard C or C++, if all your code depends on , use 'jbyte' instead, it is defined in this header, and maps to an 8-bit unsigned integer type.

Alternatively, you could define 'byte' with a typedef as in:

typedef unsigned char byte;

And ensure this is used/parsed by all your sources (e.g. put it in a shared header).

A slightly more correct way to do it is:

#include <inttypes.h>

typedef uint8_t byte;

It will be equivalent on all supported Android platforms, but requires an additional include.

(Technically, 'char' can be more than 8 bits on some really odd platforms, but none of them are ever going to be targetted by Android).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top