Error Handling: Invalid arguments 'candidates are: void * memcpy (void *, const void *,?)
Problems encountered during JNI development.
Symptoms:
Invalid arguments ' Candidates are: void * memcpy(void *, const void *, ?)Invalid arguments 'Candidates are: void * malloc(?)
You can also see the function prototype in the contained header file, as shown below:
extern __mallocfunc void* malloc(size_t);extern void* memcpy(void *, const void *, size_t);
In the error message: Invalid arguments, which means the parameter is Invalid. It is obvious that the size_t parameter is not properly identified.
Because of this analysis, this problem occurs in all methods that use size_t parameters, such as memset, memccpy, memchr, and memcmp.
There are two ways to solve this problem. First, use other methods instead of memcpy, malloc, and memset. Second: enable the system to normally identify the size_t type, which is a fundamental solution to this problem. The following provides detailed solutions for each of the two ideas.
1. Alternative Method
You can use new and strcpy to replace malloc and memcpy. Here, the malloc and memcpy methods are used. You can find corresponding methods to replace other methods.
For example:
Originally:
Const char* Tmp = env-> GetStringUTFChars (jstr_mac, NULL );
Size_tLen = strlen (tmp) + 1;
Char* Mac = (Char*) Malloc (len );
Memcpy (mac, tmp, len );
You can change it:
Const char* Tmp = env-> GetStringUTFChars (jstr_mac, NULL );
IntLen = strlen (tmp) + 1;
Char* Mac =New Char[Len];
Strcpy (mac, tmp );
Second: enable the system to recognize the size_t type
The solution is as follows:
Right-click the Project properties> C/C ++ General> Paths and Symbols.
Select the "des" label
F: \ android-ndk-r9b \ platforms \ android-19 \ arch-arm \ usr \ include
F: \ android-ndk-r9b \ toolchains \ arm-linux-androideabi-4.8 \ prebuilt \ windows \ lib \ gcc \ arm-linux-androideabi \ 4.8 \ include
This problem can be solved.
Note:
You can also add the following two header file libraries to the project's include:
F: \ android-ndk-r9b \ sources \ cxx-stl \ gnu-libstdc ++ \ 4.8 \ include
F: \ android-ndk-r9b \ sources \ cxx-stl \ gnu-libstdc ++ \ 4.8 \ libs \ armeabi-v7a \ include
----------------------------------
Welcome to browse, technical exchange, respect for labor achievements, repost, please indicate the source, thank you!
Http://blog.csdn.net/netwalk/article/details/22295585