X
xingshan_he
I have a c program that calls a java method. When trying to access the
string parms passed into the jave pointer, I get null pointer
exception.
Here is part of the code:
char *urlChar = "http://this_host/service";
char *userChar = "tester";
char *passwordChar = "tester";
char *phoneNumberChar = "1234567890";
jmethodID mid = (*env)->GetStaticMethodID(env,
cls, "getPhoneMessage",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String
Ljava/lang/String;");
if (mid == NULL) {
printf("unable to get method getPhoneMessage()...");
return;
}
jobject result = (*env)->CallStaticObjectMethod(
env, cls, mid, phoneNumberChar, urlChar, userChar, passwordChar);
--- java class ---
public class IVRPhoneUtil {
public static String getPhoneMessage(String phoneNumber, String
url, String userID, String password) throws Exception {
System.out.println("java getPhoneMessage()");
if (url == null) {
System.out.println("url is null");
}
else {
System.out.println("length " + url.length());
System.out.println("url is " + url);
}
return "test message";
}
}
-- error / stack trace ---
Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.write(Writer.java:126)
at java.io.PrintStream.write(PrintStream.java:303)
at java.io.PrintStream.print(PrintStream.java:448)
at java.io.PrintStream.println(PrintStream.java:585)
at
com.interop.ivr.IVRPhoneUtil.getPhoneMessage(IVRPhoneUtil.java:21)
Segmentation fault (core dumped)
The line that's causing the null pointer is where I tried to print out
the length of the string.
Any idea what's going wrong here?
Thanks.
XS
string parms passed into the jave pointer, I get null pointer
exception.
Here is part of the code:
char *urlChar = "http://this_host/service";
char *userChar = "tester";
char *passwordChar = "tester";
char *phoneNumberChar = "1234567890";
jmethodID mid = (*env)->GetStaticMethodID(env,
cls, "getPhoneMessage",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String
if (mid == NULL) {
printf("unable to get method getPhoneMessage()...");
return;
}
jobject result = (*env)->CallStaticObjectMethod(
env, cls, mid, phoneNumberChar, urlChar, userChar, passwordChar);
--- java class ---
public class IVRPhoneUtil {
public static String getPhoneMessage(String phoneNumber, String
url, String userID, String password) throws Exception {
System.out.println("java getPhoneMessage()");
if (url == null) {
System.out.println("url is null");
}
else {
System.out.println("length " + url.length());
System.out.println("url is " + url);
}
return "test message";
}
}
-- error / stack trace ---
Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.write(Writer.java:126)
at java.io.PrintStream.write(PrintStream.java:303)
at java.io.PrintStream.print(PrintStream.java:448)
at java.io.PrintStream.println(PrintStream.java:585)
at
com.interop.ivr.IVRPhoneUtil.getPhoneMessage(IVRPhoneUtil.java:21)
Segmentation fault (core dumped)
The line that's causing the null pointer is where I tried to print out
the length of the string.
Any idea what's going wrong here?
Thanks.
XS