So this is the first time using any of bluemix service, and I'm getting the following error and can't find any help online relating to this.
Am I missing something basic with set up?
Any help is appreciated, thanks.
Error is:
> Error: Could not find or load main class
> com.ibm.watson.developer_cloud.personality_insights.v3.Main
Screen shot: http://imgur.com/a/ArkP6
Code:
package com.ibm.watson.developer_cloud.personality_insights.v3;
import com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile;
public class Main {
public static void main(String[] args) {
System.out.println("kek");
PersonalityInsights service = new PersonalityInsights("2016-10-19");
service.setUsernameAndPassword(Blanked);
// Demo content from Moby Dick by Hermann Melville (Chapter 1)
String text = "Call me Ishmael. Some years ago-never mind how long precisely-having "
+ "little or no money in my purse, and nothing particular to interest me on shore, "
+ "I thought I would sail about a little and see the watery part of the world. "
+ "It is a way I have of driving off the spleen and regulating the circulation. "
+ "Whenever I find myself growing grim about the mouth; whenever it is a damp, "
+ "drizzly November in my soul; whenever I find myself involuntarily pausing before "
+ "coffin warehouses, and bringing up the rear of every funeral I meet; and especially "
+ "whenever my hypos get such an upper hand of me, that it requires a strong moral "
+ "principle to prevent me from deliberately stepping into the street, and methodically "
+ "knocking people's hats off-then, I account it high time to get to sea as soon as I can. "
+ "This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself "
+ "upon his sword; I quietly take to the ship. There is nothing surprising in this. "
+ "If they but knew it, almost all men in their degree, some time or other, cherish "
+ "very nearly the same feelings towards the ocean with me. There now is your insular "
+ "city of the Manhattoes, belted round by wharves as Indian isles by coral reefs-commerce surrounds "
+ "it with her surf. Right and left, the streets take you waterward.";
ProfileOptions options = new ProfileOptions.Builder().text(text).build();
Profile profile = service.profile(options).execute();
System.out.println(profile);
}
}
This sounds like a class path problem. Did you specify the jar with this class to be on your classpath when you run it (aka java -cp...)?
Related
I want to get the text of my TestObject, I use WebUI.getText(). My code works fine for one of my pages but fails for another page. I can't figure out why it fails, everything is literally the same and it should not fail. This is what I am doing:
#Keyword
public boolean verifyIPAddr(Socket socket){
//create test object for the ip header
TestObject ipHeader = new TestObject().addProperty("id", ConditionType.EQUALS, 'ipaddr-in-header')
WebUI.waitForElementPresent(ipHeader, 20, FailureHandling.OPTIONAL)
//get text (IP) from ipHeader
String ipHeaderStr = WebUI.getText(ipHeader)
KeywordUtil.logInfo("ipHeaderStr: " + ipHeaderStr.toString())
//split the ipHeaderStr so that "IP: " portion can be removed and only "0.0.0.0" portion is left
String[] ipHeaderStrArr = ipHeaderStr.split(' ')
//store the ip in a variable
String guiIPAddress = ipHeaderStrArr[1]
//get the socket side ip
String cassetteIP = socket.getInetAddress().getHostAddress()
KeywordUtil.logInfo(" address:" + cassetteIP)
//validate that both are the same
if(cassetteIP.equals(guiIPAddress)){
KeywordUtil.logger.logPassed(guiIPAddress + " IP from GUI matches: " + cassetteIP + " from socket")
return true;
}
else{
KeywordUtil.logger.logFailed(guiIPAddress + " IP from GUI does not match: " + cassetteIP + " IP from socket")
return false
}
}
]2
I am 100% it has something to do with WebUI.getText() but it's confusing me because it works for one page but fails for the other.
The following is the HTML for the working page:
The following is the HTML for the page that is not working:
Update:
I just noticed that the one that was failing, fails sometimes and sometimes it passes, I still want to know how I can guarantee the behavior to stay stable.
There are a couple of things you can try:
You can add a delay before getting the text of the element:
WebUI.delay(30)
You can prolong the wait
WebUI.waitForElementPresent(ipHeader, 60, FailureHandling.OPTIONAL)
The reason is, Katalon (Selenium) code often depends on elements outside of its sphere of influence, like load times, network traffic, computer hardware, competing race-conditions, etc.
So, even with same code, sometimes the wait times will differ and that's why it is better to use flexible waits (like waitForElement*() methods).
This is the program I'm trying to run. I have tried on two different systems and I get the exact same error message on both. I get the error message whenever I enter a price with a decimal e.g 4.2.
Code for the program:
package grocerylist;
import java.util.Scanner;
public class GroceryList {
public static void main(String[] args) {
float [] prices = new float [5];
Scanner in = new Scanner (System.in);
System.out.println("Enter 5 prices: ");
prices[0] = in.nextFloat();
prices[1] = in.nextFloat();
prices[2] = in.nextFloat();
prices[3] = in.nextFloat();
prices[4] = in.nextFloat();
float total = prices[0] + prices[1] + prices[2] + prices[3] + prices[4];
System.out.println("The total of the 5 items are: "+total);
}
}
The error message is on line 12 and goes like this:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextFloat(Scanner.java:2345)
at grocerylist.GroceryList.main(GroceryList.java:21)
C:\Users[username]\AppData\Local\NetBeans\Cache\8.2\executor-snippets\debug.xml:83: Java returned: 1
The solution was simpler than what I first imagined. #DualCoreMax had the right mindset for the solution. Which was, when the user is typing in prices the user needs to use the comma sign to diffrenciate between the integer number and decimal number.
I seriously thought I had a way more major problem on my hands here, glad is is just a matter of my own stupidity. Thank you to everyone who came to help me, a first year student.
I'm new to using FakeItEasy and rather stuck at my first attempt. The interface i want to fake has a method like this:
byte[] ReadFileChunk(string path,int offset,int count,out long size);
I would like to see how the arguments are passed on, so I'm using ReturnsLazily. Here is my attempt:
long resSize;
A.CallTo(() => dataAttributesController
.ReadFileChunk(A<string>.Ignored, A<int>.Ignored, A<int>.Ignored, out resSize))
.ReturnsLazily((string path, int offset, int count) =>
{
return Encoding.UTF8.GetBytes("You requested: " + path + "(" + offset + "," + count + ")");
})
.AssignsOutAndRefParameters(123);
This compiles, but when ran it generates this exception:
The faked method has the signature (System.String, System.Int32, System.Int32, System.Int64&), but returns lazily was used with (System.String, System.Int32, System.Int32).
Which is correct, but i can't figure out how to add the out parameter. If I change the ReturnLazily part to this:
.ReturnsLazily((string path, int offset, int count, out long size) =>
{
size = 0;
return Encoding.UTF8.GetBytes("You requested: " + path + "(" + offset + "," + count + ")");
})
it will not compile, and I don't understand the errors:
error CS1593: Delegate 'System.Func<FakeItEasy.Core.IFakeObjectCall,byte[]>' does not take 4 arguments
error CS1661: Cannot convert lambda expression to delegate type 'System.Func<string,int,int,long,byte[]>' because the parameter types do not match the delegate parameter types
error CS1677: Parameter 4 should not be declared with the 'out' keyword
For a novice like me, this reads like it doesn't like 4 parameters nor understands what to do with 'out'. Can someone please explain me how I should be reading these errors? A working example would be very welcome as well :-)
Thanks a lot!
--- EDIT ---
This seems to work:
A.CallTo(() => dataAttributesController
.ReadFileChunk(A<string>.Ignored, A<int>.Ignored, A<int>.Ignored, out resSize))
.ReturnsLazily(x =>
Encoding.UTF8.GetBytes("You requested: " + x.Arguments.Get<string>(0) + "(" + x.Arguments.Get<int>(1) + "," + x.Arguments.Get<int>(2) + ")"))
.AssignsOutAndRefParameters((long)123);
A bit less readable then I was hoping for, is this anywhere near the intended use of ReturnsLazily?
Is that interface under your control?
byte[] ReadFileChunk(string path, int offset, int count, out long size);
if so: Isn't out long size just the same as the size of the returning byte[]?
In that case I would just remove the size parameter from the interface method and use the "nice-to-read" ReturnsLazily method as you intended first.
Update: the issue I mention below was fixed in FakeItEasy release 1.15, so update to the latest version and you shouldn't have to worry about the out/ref specifiers on the methods when using ReturnsLazily.
Sorry for the delay. I'm glad you found a solution that at least functions for you.
I agree that the syntax you landed on isn't the most readable, but it does appear to be the correct one. The "convenience" versions of ReturnsLazily won't work with out/ref parameters because the lambda can't take the out/ref modifiers.
It doesn't help you today, but I've created FakeItEasy issue 168 to deal with the problem. If you have additional opinions, please drop by and comment or something.
I am trying to develop a deeper understanding of map/reduce in MongoDB.
I figure the best way to accomplish this is to look at emit's actual implementation. Where can I find it?
Even better would just be a simple implementation of emit(). In the MongoDB documentation, they show a way to troubleshoot emit() by writing your own, but the basic implementation they give is really too basic.
I'd like to understand how the grouping is taking place.
I think the definition you are looking for is located here:
https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/mr.cpp#L886
There is quite a lot of context needed though to fully understand what is going on. I confess, I do not.
1.Mongo's required JS version is no longer in O.Powell's url, which is dead. I cannot find it.
2.The below code seems to be the snippet of most interest. This cpp function, switchMode, computes the emit function to use. It is currently at;
https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/mr.cpp#L815
3.I was trying to see if emit has a default to include the _id key, which seems to occur via _mrMap, not shown here. Elsewhere it is initialized to {}, the empty map.
void State::switchMode(bool jsMode) {
_jsMode = jsMode;
if (jsMode) {
// emit function that stays in JS
_scope->setFunction("emit",
"function(key, value) {"
" if (typeof(key) === 'object') {"
" _bailFromJS(key, value);"
" return;"
" }"
" ++_emitCt;"
" var map = _mrMap;"
" var list = map[key];"
" if (!list) {"
" ++_keyCt;"
" list = [];"
" map[key] = list;"
" }"
" else"
" ++_dupCt;"
" list.push(value);"
"}");
_scope->injectNative("_bailFromJS", _bailFromJS, this);
}
else {
// emit now populates C++ map
_scope->injectNative( "emit" , fast_emit, this );
}
}
I have a serious problem I have not found any questions about on the net. When I push a localized message it only works for Swedish and not English. I have another that says that it only shows a constant for their Swedish Iphone 4. I have also tested on Iphone 3g and it has the same problem as my iphone 4, works in swedish not in english.
When displaying a popup for Iphone 4 in English, I only get the localization key I supply in my notification from the server.
Here is the string of the notification in C# that I push from a Windows Server. The extra parameters for my iphone app works totally fine in any language so it seems it has nothing to do with the server side part of the push.
int total = notification.AmountScheduledEvent + notification.AmountCourseResult + notification.AmountExam;
string locKey = (total > 1 ? "PushMessageMultiple" : "PushMessageSingle");
string msg = "{\"aps\":{"+
"\"alert\": {"+
"\"loc-key\":\"" + locKey + "\","+
"\"loc-args\":[\"" + total + "\"]},"+
"\"badge\":" + total + ","+
"\"sound\":\"default\"},"+
"\"amountSchedule\":" + notification.AmountScheduledEvent + ","+
"\"amountCourseResult\":" + notification.AmountCourseResult + ","+
"\"amountExam\":" + notification.AmountExam + "}";
In my Localizable.strings in sv.lproj:
/* push stuff */
"PushMessageMultiple" = "%# nya händelser";
"PushMessageSingle" = "1 ny händelse";
In my Localizable.strings in en.lproj:
/* push stuff */
"PushMessageMultiple" = "%# new events";
"PushMessageSingle" = "1 new event";
Here is a picture of the screen with a notification that works (Swedish)
http://img267.imageshack.us/i/img0014b.png/
Here is a picture of the screen with a notification that doesn't work (English)
http://img696.imageshack.us/i/img0015i.png/
Any idea why I get a constant instead of a message?
Try to use:
NSLocalizedString(#"PushMessageMultiple",#"");
This will dynamicaly get the correct string.