SetDataAndType method - java

As documented in Android Developers page setDataAndType method can be called in this way:
auto setDataAndTypeFunctionId = env->GetMethodID(intentClassId, "setDataAndType", "(Landroid/net/Uri;Ljava/lang/String;)V");
jstring jmime = env->NewStringUTF("video/*");
env->CallVoidMethod(context, setDataAndTypeFunctionId, intentObject, UriObject, jmime);
But when i run my app this error show on output:
java.lang.NoSuchMethodError: no method with name='setDataAndType' signature='(Landroid/net/Uri;Ljava/lang/String;)V' in class Landroid/content/Intent;

The problem is the return type, which is not void. The setDataAndType method returns an object of type Intent.
Use the following signature:
env->GetMethodID(intentClassId, "setDataAndType", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/content/Intent;");
Also, you should use CallObjectMethod instead of CallVoidMethod, although it doesn't really matter because you're not using the return value.

Related

Groovy's Getter and Setter shortcut notation incorrectly overriding function call

I'm using the update4j API within a build.gradle file and when calling the function Configuration.builder().launcher() it looks like Groovy's Getter and Setter shortcut notation is incorrectly overriding the function call with a call to getLauncher().
How should I be calling the launcher() method instead?
Relevant API docs:
Configuration
Configuration.Builder
Tasks.register('MyTask') {
Configuration.Builder update4jBuilder = = Configuration.builder().launcher("com")
println update4jBuilder.launcher
}
Execution failed for task ':MyTask'.
> No signature of method: org.update4j.Configuration$Builder.launcher?() is applicable for argument types: (String) values: [com]
Possible solutions: launcher(java.lang.String), launcher(java.lang.Class), getLauncher()
I haven't seen this affect other function calls like Configuration.builder().files() or Configuration.builder().basePath():
Tasks.register('MyTask') {
Configuration.Builder update4jBuilder = Configuration.builder().basePath("${System.properties.'user.home'}${System.properties.'file.separator'}.update4j")
println update4jBuilder.basePath
}
> Task :MyTask
C:\Users\Kyle\.update4j
#LukasKörfer
There was a special character in between launcher and () that was only seen when pasting the build.gradle in pastebin and were invisible in VSCode
Fixing it there and then copying it back into VSCode fixed it.

The constructor TFSTeamProjectCollection(String) is undefined

Trying to implement the Java SDK, following the tutorial here: https://blogs.msdn.microsoft.com/bharry/2011/05/16/announcing-a-java-sdk-for-tfs/
I have the libraries imported, but getting a compilation error
TFSTeamProjectCollection tpc =
new TFSTeamProjectCollection(BASEURL);
BASEURL is a string I defined earlier in the code.
The error is: The constructor TFSTeamProjectCollection(String) is undefined
Does anyone know how to resolve this issue?
Well, studying the C# side of things ( see here ) I can't find a constructor that would only take a String argument.
There is only a single argument constructor taking a Uri.
In other words: the fact that you your string contains a Url; and that you named it a BASEURL doesn't magically turn it from a String into a URL or URI class object.
Guessing: the ctor wants an argument of type java.net.URL which you could probably create with something like new URL(BASEURL); instead of just passing BASEURL to that constructor.
The thing is: in order to actually understand which constructors that Team Foundation class has; one would need access to the corresponding SDK from Microsoft - which you probably downloaded and and have in place. So, the only thing that you need to do ... read the javadocs!

Why do I get an error "The method ... is undefined for the type..."?

I've build a method which takes strings as input parameter. In my index.jsp page, I retrieve a GET-variable from the URL using request.getParameter(). Now, I want to call the aforementioned method on this string, but I get a compiler error saying:
The method <method name>(String) is undefined for the type __2F_<webapp name>_2F_src_2F_main_2F_webapp_2F_index_2E_jsp".
Does anyone know why I get this error and how I can get rid of it. Any help is greatly appreciated!
My code is rather lengthy, but I think this is relevant code:
categorie = request.getParameter("categorie");
if (categorie.equals("")) {
categorie = "Category;";
}
ArrayList<String> categorieen = queryCategories(categorie);
You are calling ArrayList<String> categorieen = queryCategories(categorie); and you did not define queryCategories method. Since the JSP page is compiled into a big servlet class, it tries to locate queryCategories method as member of that class and it could not find it.
Very little information. Where is your app deployed? From what I gather, it seems you either haven't restarted the deployed app or have not replaced the changed class file and haven't set some sort of "development mode" on wherein you don't require a restart for a Jsp modification.
Just replace the .jsp and JSP_NAME.class file.

NullPointerException while using jruby

I embed jruby script engine into my java program by using javax.script.ScriptEngineManager
I made some jruby code that end with do ~ end block,
after running all code, NullPointerException occured.
but code ends with any other statement, no exception occurs.
version : 1.7.19
Caused by: java.lang.NullPointerException
at org.jruby.embed.variable.Argv.updateARGV(Argv.java:169)
at org.jruby.embed.variable.Argv.retrieve(Argv.java:158)
at org.jruby.embed.variable.VariableInterceptor.retrieve(VariableInterceptor.java:154)
at org.jruby.embed.internal.BiVariableMap.retrieve(BiVariableMap.java:378)
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:124)
in ARGV.java updateARGV
if (vars.containsKey((Object)name)) {
var = vars.getVariable((RubyObject)receiver.getRuntime().getTopSelf(), name);
var.setRubyObject(argv);
vars.getVariable returned null because of isReceiverIdentical return false
in BiVariableMap.java
if (var.isReceiverIdentical(receiver)) {
return var;
}
In isReceiverIdentical, this method just compare receiver with BiVariable's receiver usgin '=='.
Is this jruby bug? Or do I have to do something for this?
If you need more information about this problem, plz comment it!
I got ScriptEngine(engine) from ScriptEngineManager and set some java instance and method like this
engine.put("this", console);
engine.eval("$command = $this.java_method :command, [java.lang.String]");
here is my test ruby code. result and tab is java object
that has some method return String and list.
result = $command.call "something to pass"
puts result.getMessage
tabular = result.getData
tabular.each do |tab|
rows = tab.getRows
rows.each do |row|
puts row
end
puts tab.getColumnNames
end
I had created ruby type object in my java code by creating new Ruby object...
This causes checking fail in updateARGV because a receiver that register variable in BiVariableMap and another receiver that update variable are different.
So, I got a Ruby object from new ScriptingContainer(from it we can always get a same Ruby object if local context is singleton) and used it to create new ruby type object in my java code.
Reference: https://github.com/jruby/jruby/wiki/RedBridge#Singleton

Invoke getMessageWaitingIndicator count of PhoneBase.java

I am trying to retrieve count of voicemail .For this I am trying to call getMessageWaitingIndicator method of PhoneBase.java.
My Code is as given below
Class<?> class2=Class.forName("com.android.internal.telephony.PhoneBase");
Method method=class2.getMethod("getMessageWaitingIndicator");
Boolean returnValue=(Boolean) method.invoke(class2);
But Everytime I am getting an exception as mentioned below :
java.lang.IllegalArgumentException: expected receiver of type com.android.internal.telephony.PhoneBase,
but got java.lang.class<com.android.internal.telephony.PhoneBase>
I don't understand it. How can I fix this issue?
The instruction:
method.invoke (stringValue);
needs the object in which the method will be invoked.
method = class2.getMethod('myFunction',String.class);
method.invoke(someInstanceOfMyActivity, stringValue);
Documentation:
http://docs.oracle.com/javase/6/docs/api/java/lang/reflect/Method.html
Edit.
You can also look at the answer to the very close question here:
Android Reflection Method Error

Categories