JTwitter : getStatus() - java

I'm creating a desktop Twitter client in Java and I'm using JTwitter.
I tested a few lines of code with this library, which seems good, but I'm stuck at one point.
When running my app, Eclipse prints :
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at winterwell.jtwitter.InternalUtils.asMap(InternalUtils.java:170)
at winterwell.jtwitter.Twitter.getStatus(Twitter.java:1646)
at Twittshader.main(Twittshader.java:34)
If you want to see the code (oauthClient and twitter objects are declared, I don't think the problem comes from these) :
oauthClient.authorizeDesktop();
String v = oauthClient.askUser("Please enter the verification PIN from Twitter");causes that.
oauthClient.setAuthorizationCode(v);
String[] accessToken = oauthClient.getAccessToken();
// Works through all the program but crashes at this point
System.out.println(twitter.getStatus("ShadeosIsaac"));
twitter.setStatus("Running some tests");
I really don't know why it is crashing. I'm pretty sure it is quite a simple thing, but I'm not sure what to do. Ideas ?

Can I ask: What version of the JTwitter jar do you have?
You can find this with: System.out.println(Twitter.version);

Related

only builtin utterances working ASK

I'm developing a skill in Amazon Alexa. I'm trying to test the same using echosim.io but the problem is as below.
My Skill name is MyBot and the same is invocation name.
In echosim.io, When I say Alexa Launch MyBot, it gives the welcome response (The help response that I've coded in). When I say help, it gives me the help response that I've entered.
I've 4 intents say
FaqIntentOne
FIntentOne
FaqIntentTwo
FIntentTwo
And my Sample utterances are as below.
FaqIntentOne what is first answer
FIntentOne give me first answer
FaqIntentTwo what is second answer
FIntentTwo give me second answer
When I run these, Alexa doesn't give me a response.
I've the correct methods and the correct response set there. please let me know why it is not working for the utterances other than the built in ones.
when test in Alexa's test interface in developer.amazon.com, it is giving me the correct response.
This is quite confusing.
Below is how it looks in my code.
if ("FaqIntentOne".equals(intentName) || "FIntentOne".equals(intentName)) {
return getFirstHelp(intent, session);
}
else if ("FaqIntentTwo".equals(intentName) || "FIntentTwo".equals(intentName)) {
return getSecondHelp(intent, session);
}
Thanks
Though Amazon has referred people to echosim, it is not 'official' (it was developed by a 3rd party), so if it works in Amazon's test environment and not in echosim then it is possible that the issue is with echosim.
Otherwise I think you are going to need to look more closely at what is happening in your code, ie. debug it or put in some print statements and compare what happens when invoked in those 2 ways.
If you are running in Lambda - seems to be the most common - then you will need to take a look at CloudWatch logs.

Error NullPointer Neuroph doOneLearningIteration

I'm using Neuroph 2.9 framework to code ANN to predict housing prices. I want get every error every time run every epoch (to show the improve of error on chart) but this cause error.
// create multi layer perceptron
System.out.println("Creating neural network");
MultiLayerPerceptron neuralNet = new MultiLayerPerceptron(
TransferFunctionType.SIGMOID, inputsCount, hiddentsCount1,
outputsCount);
// set learning parameters
MomentumBackpropagation learningRule = new MomentumBackpropagation();
learningRule.setLearningRate(0.3);
learningRule.setMomentum(0.5);
learningRule.setNeuralNetwork(neuralNet);
learningRule.setTrainingSet(TrainSet);
learningRule.doOneLearningIteration(TrainSet);
I get this:
Exception in thread "main" java.lang.NullPointerException
at org.neuroph.nnet.learning.MomentumBackpropagation.updateNeuronWeights(MomentumBackpropagation.java:72)
at org.neuroph.nnet.learning.BackPropagation.calculateErrorAndUpdateOutputNeurons(BackPropagation.java:83)
at org.neuroph.nnet.learning.BackPropagation.updateNetworkWeights(BackPropagation.java:53)
at org.neuroph.core.learning.SupervisedLearning.learnPattern(SupervisedLearning.java:190)
at org.neuroph.core.learning.SupervisedLearning.doLearningEpoch(SupervisedLearning.java:165)
at org.neuroph.core.learning.IterativeLearning.doOneLearningIteration(IterativeLearning.java:245)
at com.thao.Main.main(Main.java:76)
The problem is when I use : learningRule.learn(TrainSet); it's ok, no error come out. The documentation so bad to differ functions to chose right function to run the right thing I want.
The thing I found is that doOneLearningIteration function didn't work because inside them. It's not initiated. Therefore, to run, we need to override or run 1 epoch and then doOneLearningIteration.
That's work for me.

Java Play Mustache NPE Error

We are getting a mustache play error in production (amazon linux EC2 AMI) but not in development (MACs) and we have tried upgrading the jvm, using the jdk instead, and changing from a tomcat deploy model to match our development environments as much as possible but nothing is working. Please any help would be greatly appreciated. We have lots of shared code in java and javascript using mustache and it would be a big deal to rewrite everything if we had to ditch mustache on the java side.
20:48:52,403 ERROR ~
#6al2dd0po
Internal Server Error (500) for request GET /mystuff/people
Execution exception (In {module:mustache-0.2}/app/play/modules/mustache/MustacheTags.java around line 32)
NullPointerException occured : null
play.exceptions.JavaExecutionException
at play.templates.BaseTemplate.throwException(BaseTemplate.java:90)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:257)
at play.templates.Template.render(Template.java:26)
at play.templates.GroovyTemplate.render(GroovyTemplate.java:187)
at play.mvc.results.RenderTemplate.<init>(RenderTemplate.java:24)
at play.mvc.Controller.renderTemplate(Controller.java:660)
at play.mvc.Controller.renderTemplate(Controller.java:640)
at play.mvc.Controller.render(Controller.java:695)
at controllers.MyStuff.people(MyStuff.java:183)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
at play.modules.mustache.MustacheTags._template(MustacheTags.java:32)
at play.modules.mustache.MustacheTags$_template.call(Unknown Source)
at /app/views/User/people.html.(line:22)
at play.templates.GroovyTemplate.internalRender(GroovyTemplate.java:232)
... 13 more
Seems the issue is with the threadlocal. In Prod as per my logs, the session gets initialized with the main thread.
[2012-06-30 18:35:38,102] INFO 10097[**main**] - Mustache module initialized
However, MustacheTag tries to access with various thread like this during request.
[2012-06-30 17:48:44,669] INFO 66048[**play-thread-1**] - [{module:mustache-0.2}/app/play/modules/mustache/MustacheTags.java:46] _meta() :: MustachePlugin.session():null
So I changed the implementation of MustachePlugin like this.Changed line commented out:
//private static ThreadLocal<MustacheSession> session_ = new ThreadLocal<MustacheSession>();
private static MustacheSession _session = null;
public static MustacheSession session(){
//return session_.get();
return _session;
}
public void onConfigurationRead(){
// some code
_session = new MustacheSession(compiler, root);
// some code
}
And it is working fine now in prod mode! I see no reason why it should have been in a ThreadLocal in the first place as the session gets initialized at startup!
your issue is difficult to reproduce so i'll give few pointers here. you have tried to eliminate of issue being env issue. so other possible issues could be
data issue: many times reason for production issue is usually difference in actual data and test data. check if its data issue which is casuing NPE.
code issue: Is there something at people.html.(line:22) causing issue. first try removing / altering that to check if thats causing issue. Or can you get source code of mustache (exact version which you are using) and see what object its trying to create and where its failing.
Properties file for different environments: do you have different proprties file for each env? If yes, have u missed on any property for prod env?
You have a NullPointerException on MustacheTags.java at line 32.
This means that you are probably calling a method of the Mustache library and passing a null value.
Try logging all the parameters you transfer to this method (MyStuff.java line 183?).
You can look at the source code of MustacheTags here, it might help you understand what values you are passing and what should be passed.

Eclipse - Command line URL argument cutting off https

EDIT: Code for InstallCerts is here:
http://code.google.com/p/java-use-examples/source/browse/trunk/src/com/aw/ad/util/InstallCert.java
I am trying to run a java program in eclipse that takes a URL (eg https://myurl.com) as an argument. When I go to Run Configurations -> Arguments and paste in the URL, it looks fine. I click Apply.
The problem starts when I click Run. For some reason, eclipse removes the https: at the start of the URL and I get an error saying:
Exception in thread "main" java.lang.NumberFormatException: For input string: "//myurl.com"
Notice the lack of https:?
Anyway, if someone can point me in the right direction to resolve this, I'd be very grateful.
I should also point out, I tried to create a Variable as well, to hold the URL, but I got the same error. Likewise when I quoted the URL.
Thanks.
You are getting a "NumberFormatException" which means you are trying to convert a String to int in your code . I think thats the real problem.
Quote it.
"https://myurl.com"
EDIT : I just tried quote/unquote - it works either way. Can you post your code?
Cheers,Eugene
The trick is that class searches for port. Do not use https://, instead refer to secure port e.g. my.site.com:443!

Error message when querying the datastore

I am new to Java, Eclipse, Google App Engine and the Datastore and am writing my first app to teach myself some new technology both for work and for professional development purposes.
I have a Java app that successfully saves and retrieves data from a datastore that I have created based upon the key. I now want to be able to do more general queries based upon other information in my datastore for meta-code such as:
select key_column from my datastore where other_column = "data to be searched"
To achieve this, I have done some on-line reading and referenced the O'Reilly book Programming Google App Engine. I started with the sample code and it fails with the error message:
An error occured while attempting to contact the server.
Please check your network connect and try again
My code at this point is:
Query q = new Query("Force");
q.addFilter("ForceName", Query.FilterOperator.EQUAL, input);
PreparedQuery pq = datastore.prepare(q);
for (Entity forceresult : pq.asQueryResultIterable()); {
String newinput = (String) result.getProperty("ForceCode");
}
The error occurs on the last String netinput line.
The datastore code exists and is good - I have successfully written/read from it.
The documentation on the above sample code is lacking however to a newbie in this area, for instance: I am assuming that the Entity 'forceresult' only exists within the for loop and cannot be referenced from outside it - that is fine with me.
However, in the String newinput line, I have coded result.getProperty even though it seems to me that it should be forceresult.getProperty as this is what I want to refer to.
When I code that however, Eclipse tells me that it cannot resolve forceresult even though an Entity has been defined in the line above.
Is result a reserved word that I missed the significance of?
Is my code wrong in any other respect? Perhaps I am not understanding asQueryResultIterable properly yet?
How should I interpret the error message:
An error occured while attempting to contact the server.
Please check your network connect and try again
I hope someone can point me in the right direction either with a specific answer or advice on where to go next in my learning curve.
You have an error in your loop (a ; too much :)). Try this:
for (Entity forceresult : pq.asQueryResultIterable()) {
// ^ ; was here
String newinput = (String) result.getProperty("ForceCode");
}
Thus your loop was actually empty and the result.getProperty(...) got called outside, where forceresult isn't defined.

Categories