我在使用Java和JNI接口时遇到问题。 我已经建立了一个连接到某些网站并打印内容并将内容发送到jni c ++的系统。 但是我有一些问题。当我尝试将BufferedReader字符串发送给jni时,我得到了一个Java空指针异常
所以你能帮我吗!谢谢 ! C ++:
#include </jdk1.8.0_191/include/jni.h>
#include "/build/classes/crawlhttpsmemoryc_Crawlhttpsmemoryc.h"
JNIEXPORT jstring JNICALL Java_crawlhttpsmemoryc_Crawlhttpsmemoryc_seaubsiteco
(JNIEnv * env, jobject xtest, jstring xsd) {
std::string strServiceIp(env->GetStringUTFChars(xsd, NULL));
std::cout << "du c++" << strServiceIp;
}
还有java:
public static void main(String[] args) throws MalformedURLException, IOException {
String httpsURL = "https://gnu.org";
URL myUrl = new URL(httpsURL);
HttpsURLConnection conn = (HttpsURLConnection)myUrl.openConnection();
conn.setRequestProperty("Content-Language", "en-US");
InputStream is = conn.getInputStream();
System.out.println(org.apache.commons.io.IOUtils.toString(is));
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
String inputLine;
String x = "";
StringBuilder xbuf = new StringBuilder();
while ((inputLine = br.readLine()) != null) {
xbuf.append(inputLine);
}
x= xbuf.toString();
new Crawlhttpsmemoryc().seaubsiteco(x);
堆栈跟踪:
Exception in thread "main" java.lang.NullPointerException at crawlhttpsmemoryc.Crawlhttpsmemoryc.seaubsiteco(Native Method)