setContextPath() not found - java

I am trying to use the library Porcupine on Android. I have now downloaded a Rhino context file (.rhn) but can't find a way how to implement that file into my code.
The documentation says that I should use setContextPath() but this gives me the error:
Cannot resolve method 'setContextPath' in 'Builder'
That's how I tried it:
try {
porcupineManager = new PorcupineManager.Builder()
.setModelPath("porcupine_params_de.pv")
.setAccessKey(ACCESS_KEY)
.setKeywordPath("my_file_de_android_v2_0_0.ppn")
.setContextPath("my_file_de_android_v2_0_0.rhn");
.setSensitivity(0.7f).build(
getApplicationContext(),
porcupineManagerCallback);
porcupineManager.start();
}
...
I don't know what this method is good for since I can't even find it in its class.
So how can I use my .rhn file?

In the sample code from the link you provide, this method is called on different class:
PicovoiceManager picovoiceManager = new PicovoiceManager.Builder()
.setAccessKey("${ACCESS_KEY}")
.setKeywordPath("${KEYWORD_FILE_PATH}")
.setWakeWordCallback(wakeWordCallback)
.setContextPath("${CONTEXT_FILE_PATH}")
.setInferenceCallback(inferenceCallback)
.build(context);
you use PorcupineManager while sample code uses PicovoiceManager.

Related

Chunked uploading of media with Twitter4J

I am trying to upload a video on Twitter. I am using the following code:
private UploadedMedia uploadMediaChunkedInit(long size) throws TwitterException {
return new UploadedMedia(post(
conf.getUploadBaseURL() + "media/upload.json",
new HttpParameter[] { new HttpParameter("command", CHUNKED_INIT),
new HttpParameter("media_type", "video/mp4"),
new HttpParameter("total_bytes", size) }).asJSONObject());
}
Where I am getting following error:
Method post is not defined
I got this code from here:
https://github.com/yusuke/twitter4j/pull/226/commits/73b43c1ae4511d3712118f61f983bcbca4ef0c59
Those methods are private implementation details/utilities of the TwitterImpl class.
See lines 1844-1860 and lines 1862-1878
(notice they are private).
You are approaching this incorrectly. Never should you have to call an internal implementation detail. Instead, use the public API of Twitter4J. You should use the uploadMediaChunked method instead. There is currently no javadoc I can link you to (since it's a relatively new feature).
I also see that this feature is not yet released. For now, you can build Twitter4J yourself and then use its public API (instead of copying source code into your own project).

How to run a .m (matlab) file through java and matlab control?

I have 2 .m files. One is the function and the other one (read.m) reads then function and exports the results into an excel file. I have a java program that makes some changes to the .m files. After the changes I want to automate the execution/running of the .m files. I have downloaded the matlabcontrol.jar and I am looking for a way to use it to invoke and run the read.m file that then reads the function.
Can anyone help me with the code? Thanks
I have tried this code but it does not work.
public static void tomatlab() throws MatlabConnectionException, MatlabInvocationException {
MatlabProxyFactoryOptions options =
new MatlabProxyFactoryOptions.Builder()
.setUsePreviouslyControlledSession(true)
.build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);
MatlabProxy proxy = factory.getProxy();
proxy.eval("addpath('C:\\path_to_read.m')");
proxy.feval("read");
proxy.eval("rmpath('C:\\path_to_read.m')");
// close connection
proxy.disconnect();
}
Based on the official tutorial in the Wiki of the project, it seems quite straightforward to start with this API.
The path-manipulation might be a bit tricky, but I would give a try to loading the whole script into a string and passing it to eval (please note I have no prior experience with this specific Matlab library). That could be done quite easily (with joining Files.readAllLines() for example).
Hope that helps something.

How to use Interface Example.PropertySelector

I want to use PropertySelector in Example in hibernate but I didn't find any example on net that guide how to use it.
I found document here http://docs.jboss.org/hibernate/orm/3.5/javadoc/org/hibernate/criterion/Example.PropertySelector.html
Basically what I am trying to do is
Example example = Example.create(user);
PropertySelector propertySelector;
propertySelector.include(user, "emailId", org.hibernate.type.Type);
It gives error org.hibernate.type.Type cannot be resolved to a variable, so what to use in third argument?

Restlet : Unable to find a converter for this representation : [application/json,UTF-8]

I have researched this quite heavily but have been unable to find a solution. I have created the simplest unit test to fetch a single entity but am still receiving the "Unable to find converter" exception. I have included the org.restlet.ext.servlet.jar,org.json.jar and org.restlet.ext.net.jar in my class path. I am also able to see the json returned and have been able to print using the cr.get(MediaType.APPLICATION_JSON) method.
ClientResource cr = new ClientResource("http://localhost:8888/r/establishment/29");
Establishment est = cr.get(Establishment.class);
System.out.println("Establishment name is " + est.getName());
I am using restlet-gae-2.1rc6 on GAE vs 1.7.1
You need to register a converter. Example:
Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
See a question with the same solution but a different problem: Android to gae restlet example doesn't work on the Android side
I found the solution here: https://stackoverflow.com/a/5205993/435605

protocol buffer cannot find symbol newBuilder

I am new to protocol buffer from google so I tried the Java tutorial and everything goes well until I am trying to make an instance of the protocol class. So I tried to make my own proto file but I had the same problem. The problem lies in this piece of code:
AddressBook.Builder address = new AddressBook.newBuilder();
On the newBuilder() part I am getting a cannot find symbol error. In the comments in the file generated by protoc it says to use the newBuilder() to make an instance of the class and I can't find the problem. Does anyone know the problem and is there a solution?
This is the problem:
new AddressBook.newBuilder();
That syntax is half way between a method call and a constructor call. newBuilder() is just a static method. You just need:
AddressBook.Builder builder = AddressBook.newBuilder();

Categories

Resources