Why is String One = "Øzil" not a statement? - java
Here is my little example code:
String legend = "Øzil";
if (legend.equals("Øzil")) {
System.out.println("You should have bought him Moyes");
}
Whenever I try to compile this code I get this error message: error: Not a Statement* String legend = Øzil"
You have missed ) in the end of if statement
if (legend.equals("Øzil") {
^_____see here
It's because of the funny character you are using, you should find its ASCII code and use it instead.
EDIT: ooops now I see I got it wrong :)
try this one :
String legend = "Øzil";
if (legend.equals("Øzil")) {
System.out.println("You should have bought him Moyes");
}
Add end bracket ) to the if condition:
From
if (legend.equals("Øzil") {
to
if (legend.equals("Øzil")) {
Related
adding inner label gives error on string variable
I have a special case in my code where a label would fix possible issues start: String zipCodes1 = "90019,90036,90016,90005,90010,90018,90020,90004,90048,90035,90211,90006,90038,90008,90089,90062,90007,90028,90034,90212,90232,90231,90233,90057,90209,90213,90070,90029,90069,90015,90056,90037,90017,90067,90043,90046,90026,90071,90014,90230,90064,90099,90302,90189,90011,90030,90050,90051,90052,90053,90054,90055,90060,90072,90074,90075,90076,90078,90080,90081,90082,90083,90086,90087,90088,90093,90024,90009,90013,90068,90090,90079,90012,90210,90021,90025,90306,90307,90308,90309,90310,90312,90311,90095,90305,91608,90027,90084,90066,90301,90073,90094,90047,91522,91604,90039,90003,90044,91602,90031,91204,91523,90033,90295,90001,90045,90077,91521,90065,90096,90404,90292,90405,90303,90058,90294,90304,90291,91209,91221,91222,91224,91225,91226,91210,91205,90023,91203,91601,91393,91506,91423,90063,90002,90403,90255,91607,91603,91609,91610,91611,91612,91614,91615,91616,91617,91618,90406,90407,90408,90409,90410,90411,90049,91201,91505,91502,90401,90251,90296,90293,91503,91507,91508,91510,91526,90402,91202,90250,91413,90032,90042,90061,90270,90041,91495,90245,91403,91606,90059,90249,91401,91501,91207,91206,91504,90261,90022,90247,91754,90201,90222,90091,90260,91208,91411,91803,90040,91030,91404,91407,91408,91409,91410,91470,91482,91496,91499,90506,90280,91605,90267,90266,90262,91436,91353,91031,91105,90248,91416,91426,91801,90272,91804,90504,90278,90202,91405,91123,91756,90223,90224,91802,91896,91899,91046,91714,91715,91352,91103,91716,91021,91316,91020,91755,90254,91102,91109,91110,91114,91115,91116,91117,91118,91121,91124,91125,91126,91129,91182,91184,91185,91188,91189,90220,91101,91406,91106,90640,91012,90747,91412,91214,91108,90746,91778,91402,91356,90239,90221,90240,91776,90723,90242,91043,90241,90503,90661,90662,90507,90508,90509,90510,91770,91775,91357,91104,90502,91331,91199,90660,90501,91334,91041,90277,91343,90749,91337,91003,91771,91772,91001,91385,91335,91333,90290,90805,90895,90745,91346,91395,90671,91107,91325,90706,90610,91040,90606,91733,91364,91371,91327,91328,91329,91345,90505,91780,91731,90264,91042,91341,91330,90707,90810,91365,91340,91007,91396,90710,91306,90807,90717,90712,90711,90714,90651,90652,91734,91735,91324,90650,91367,91305,91308,91309,91303,90601,91025,91394,90607,90608,90609,90670,91006,91066,91077,90602,91372,91024,91011,91732,90806,91392,90713,90748,90274,90744,91302,90702,90701,91344,90755,91746,90605,91023,90703"; String[] zipArray1 = zipCodes1.trim().split(","); Random zipIndex1 = new Random(); int randomIndex1 = zipIndex1.nextInt(395); System.out.println("Zip bad! New zip = "+zipArray1[randomIndex1]+""); driver.findElement(By.xpath("//android.widget.EditText[#index='0']")).sendKeys(zipArray1[randomIndex1]); Thread.sleep(750); driver.pressKey(new KeyEvent(AndroidKey.BACK)); Thread.sleep(1000); driver.findElement(saveLoc).click(); Thread.sleep(5750); if (driver.findElements(By.xpath("//*[#text='Check your zip and try again']")).isEmpty()) { System.out.println("Zip code change successful"); } else { continue start; } } but right after start on String zipCodes1 it gives me an error saying that: String cannot be resolved to a variable and zipCodes1 cannot be resolved to a variable why is this happening? is there a way to fix this?
Try doing this while(true){ String zipCodes1 = "90019,90036,90016,90005,90010,90018,90020,90004,90048,90035,90211,90006,90038,90008,90089,90062,90007,90028,90034,90212,90232,90231,90233,90057,90209,90213,90070,90029,90069,90015,90056,90037,90017,90067,90043,90046,90026,90071,90014,90230,90064,90099,90302,90189,90011,90030,90050,90051,90052,90053,90054,90055,90060,90072,90074,90075,90076,90078,90080,90081,90082,90083,90086,90087,90088,90093,90024,90009,90013,90068,90090,90079,90012,90210,90021,90025,90306,90307,90308,90309,90310,90312,90311,90095,90305,91608,90027,90084,90066,90301,90073,90094,90047,91522,91604,90039,90003,90044,91602,90031,91204,91523,90033,90295,90001,90045,90077,91521,90065,90096,90404,90292,90405,90303,90058,90294,90304,90291,91209,91221,91222,91224,91225,91226,91210,91205,90023,91203,91601,91393,91506,91423,90063,90002,90403,90255,91607,91603,91609,91610,91611,91612,91614,91615,91616,91617,91618,90406,90407,90408,90409,90410,90411,90049,91201,91505,91502,90401,90251,90296,90293,91503,91507,91508,91510,91526,90402,91202,90250,91413,90032,90042,90061,90270,90041,91495,90245,91403,91606,90059,90249,91401,91501,91207,91206,91504,90261,90022,90247,91754,90201,90222,90091,90260,91208,91411,91803,90040,91030,91404,91407,91408,91409,91410,91470,91482,91496,91499,90506,90280,91605,90267,90266,90262,91436,91353,91031,91105,90248,91416,91426,91801,90272,91804,90504,90278,90202,91405,91123,91756,90223,90224,91802,91896,91899,91046,91714,91715,91352,91103,91716,91021,91316,91020,91755,90254,91102,91109,91110,91114,91115,91116,91117,91118,91121,91124,91125,91126,91129,91182,91184,91185,91188,91189,90220,91101,91406,91106,90640,91012,90747,91412,91214,91108,90746,91778,91402,91356,90239,90221,90240,91776,90723,90242,91043,90241,90503,90661,90662,90507,90508,90509,90510,91770,91775,91357,91104,90502,91331,91199,90660,90501,91334,91041,90277,91343,90749,91337,91003,91771,91772,91001,91385,91335,91333,90290,90805,90895,90745,91346,91395,90671,91107,91325,90706,90610,91040,90606,91733,91364,91371,91327,91328,91329,91345,90505,91780,91731,90264,91042,91341,91330,90707,90810,91365,91340,91007,91396,90710,91306,90807,90717,90712,90711,90714,90651,90652,91734,91735,91324,90650,91367,91305,91308,91309,91303,90601,91025,91394,90607,90608,90609,90670,91006,91066,91077,90602,91372,91024,91011,91732,90806,91392,90713,90748,90274,90744,91302,90702,90701,91344,90755,91746,90605,91023,90703"; String[] zipArray1 = zipCodes1.trim().split(","); Random zipIndex1 = new Random(); int randomIndex1 = zipIndex1.nextInt(395); System.out.println("Zip bad! New zip = "+zipArray1[randomIndex1]+""); driver.findElement(By.xpath("//android.widget.EditText[#index='0']")).sendKeys(zipArray1[randomIndex1]); Thread.sleep(750); driver.pressKey(new KeyEvent(AndroidKey.BACK)); Thread.sleep(1000); driver.findElement(saveLoc).click(); Thread.sleep(5750); if (driver.findElements(By.xpath("//*[#text='Check your zip and try again']")).isEmpty()) { System.out.println("Zip code change successful"); break; } }
From JLS 14.7. Labeled Statements LabeledStatement: Identifier : Statement LabeledStatementNoShortIf: Identifier : StatementNoShortIf The Identifier is declared to be the label of the immediately contained Statement. Unlike C and C++, the Java programming language has no goto statement; identifier statement labels are used with break or continue statements (§14.15, §14.16) appearing anywhere within the labeled statement. The scope of a label of a labeled statement is the immediately contained Statement. So you can't use like below: start: String zipCodes1 = "..." One example you can use this with loops like answer by #Shrey Garg
OpenOffice xSentenceCursor stuck at end of paragraph
I am using this routine to iterate over sentences in an OpenOffice document: while (moreParagraphsOO) { while (moreSentencesOO) { xSentenceCursor.gotoEndOfSentence(true); textSentence = xSentenceCursor.getString(); xTextViewCursor.gotoRange(xSentenceCursor.getStart(), false); xTextViewCursor.gotoRange(xSentenceCursor.getEnd(), true); if (!textSentence.equals("")) { return textSentence; } moreSentencesOO = xSentenceCursor.gotoNextSentence(false); } moreParagraphsOO = xParagraphCursor.gotoNextParagraph(false); moreSentencesOO = xSentenceCursor.gotoStartOfSentence(false); } It works fine unless it finds a paragraph which ends with ". ", this is, a period and one or several whitespaces after it. In that case it enters and infinite loop executing the while (moreSentencesOO) ... moreSentencesOO = xSentenceCursor.gotoNextSentence(false); endlessly. I am not so proeficient with OpenOffice API, and I am quite stuck here. Any ideas? Thanks. EDIT: I have come with a somewhat awkward patch consisting in checking the current position of the cursor, and if it does not advance between two iterations, jump to next paragraph: while (moreParagraphsOO) { while (moreSentencesOO) { /**********************************/ int previousPosX = xTextViewCursor.getPosition().X; int previousPosY = xTextViewCursor.getPosition().Y; /*********************************/ xSentenceCursor.gotoEndOfSentence(true); textSentence = xSentenceCursor.getString(); xTextViewCursor.gotoRange(xSentenceCursor.getStart(), false); xTextViewCursor.gotoRange(xSentenceCursor.getEnd(), true); if (!textSentence.equals("")) { return textSentence; } moreSentencesOO = xSentenceCursor.gotoNextSentence(false); /**********************************/ if (previousPosX == xTextViewCursor.getPosition().X && previousPosY == xTextViewCursor.getPosition().Y){ xParagraphCursor.gotoNextParagraph(false); } /**********************************/ } moreParagraphsOO = xParagraphCursor.gotoNextParagraph(false); moreSentencesOO = xSentenceCursor.gotoStartOfSentence(false); } It seems to work, but I am unsure about whether it could introduce future problems. I would rather prefer an "elegant" solution.
According to gotoNextSentence(), it should only return true if the cursor was moved, so this is a bug. Consider filing a report. The problem seems to occur when isEndOfSentence() but not isStartOfSentence(). So test for that instead of getPosition(). Here is Andrew Pitonyak's Basic macro that I modified to include this fix. Sub CountSentences oCursor = ThisComponent.Text.createTextCursor() oCursor.gotoStart(False) Do nSentences = nSentences + 1 If oCursor.isEndOfSentence() And Not oCursor.isStartOfSentence() Then oCursor.goRight(1, False) End If Loop While oCursor.gotoNextSentence(False) MsgBox nSentences & " sentences." End Sub
NoraUI - "Cannot infer Type argument" error using Result.Warning<> in a custom step
I need to raise a warning during one of my scenario but i don't stop to have this error appearing : "Cannot infer type arguments for Result.Warning<>" I actually tried to raise the Warning the same way i was raising Failure until now : new Result.Warning<>(targetKey, Messages.format(TaroMessages.WARNING_RESOURCES_VALUE_DIFFERENCE_AFTER_REAFFECTATION, existing_value, new_value), true, oscarAccesClientPage.getCallBack()); The custom step i am using it inside is the following : I'm trying to go over a list of Element and checking that the existing value of them is the same or not as the one saved before. protected void checkXyResourcesValue(Integer xyIterator, List<WebElement> elements, String keyParameter) throws TechnicalException, FailureException { try { Integer resIterator = 1; for(WebElement element : elements) { String targetKey = "XY" + xyIterator + "RES" + resIterator + keyParameter; String new_value = element.getAttribute(VALUE) != null ? element.getAttribute(VALUE) : element.getText(); String existing_value = Context.getValue(targetKey) != null ? Context.getValue(targetKey) : targetKey; if (new_value != existing_value) { new Result.Warning<>(targetKey, Messages.format(TaroMessages.WARNING_RESOURCES_VALUE_DIFFERENCE_AFTER_REAFFECTATION, existing_value, new_value), true, oscarAccesClientPage.getCallBack()); } resIterator++; } } catch (Exception e) { new Result.Failure<>(e.getMessage(), Messages.format(TaroMessages.FAIL_MESSAGE_ACCES_CLIENT_XY_CHECK_RESOURCES_VALUE, keyParameter, xyIterator), true, oscarAccesClientPage.getCallBack()); } } For the method to check and saved value I actually inspired myself for the piece of code from NoraUI to save a value on Context or read it from. I'm using Eclipse Luna 4.4.2 and i try to compile using JDK1.8.0_131. It may be more related to me not knowing how this work in Java than a real problem so thank you in advance for your help or insights. Don't hesitate to ask if you need more information on the piece of code or the context.
new Result.Warning<>(targetKey, Messages.format(TaroMessages.WARNING_RESOURCES_VALUE_DIFFERENCE_AFTER_REAFFECTATION, existing_value, new_value), true, 0); use 0 if you do not use any Model (data serialized) or use id of your Object in the serial.
blank number field causing fatal exception even if checked
I'm trying to make sure when you forget to enter a number that my app won't crash, I have a text field called edit that only accepts numbers, I am getting this error when i test what happens if you don't enter anything in the text field, which is a numeric text field and only brings up the number keyboard on your device, so you cant enter text at all just numbers can anyone tell me what I'm doing wrong? this is the error message: FATAL EXCEPTION: main Process: com..rhgtimecard, PID: 27379 java.lang.NumberFormatException: Invalid int: "" at com..rhgtimecard.TimeIn$2.onClick(TimeIn.java:478) And this is the related code block if (login == 1) { int getemn = 0; if (!edit.equals("")) {//**if you didn't enter anything but pressed set anyway this should stop the rest of the code block. //I tried setting this to if (edit != null) didn't work either, tried setting this to if (!edit.equals()) but it wont //compile like that at all** getemn = Integer.parseInt(edit.getText().toString());//**this is line 478 that throws the fatal exception error** String getemp = edit2.getText().toString(); String allpass = "Passwords"; SharedPreferences loadPass = getSharedPreferences(allpass, MODE_PRIVATE); String empStrng = String.valueOf(getemn); String passes = "pass"; if (getemn < 13) { passes = "pass" + empStrng; g.setData4(getemn, loadPass.getString(passes, "0123")); } String[] pass = g.getData4(); if (i == 0 && getemp.equals(pass[getemn])) { g.setData3(getemn); Logscript(); } if (i == 0 && !(getemp.equals(pass[getemn]))) { tfone.setText("No matches found"); tftwo.setText("Enter password"); edit2.setText(""); i = 1; } } } can anyone tell me where I went wrong here or how to actually check if someone entered a number?
Try this: if(!edit.getText().toString().equals(""))
if (!edit.equals("")) This is the line probably you should be changing to: if(!edit.getText().toString().equals("")) Right now you are checking if the actual object of edit equals the blank number, not the text of the edit box. If you are setting the integer to 0 by default, you could do something like this: getemn = Integer.parseInt(edit.getText().toString().equals("") ? "0" : edit.getText.toString() );
Add this property to EditText in XML file android:inputType="number" And in Java : if(!editText.getText().toString()isEmpty()){ //Your content here }
Trying to get program to repeat
The program checks to see if the email address entered contains a # and a .edu if it doesn't it needs to go back through the steps, I think I can use a do-while,but I haven't got one to work yet, how would I nest my if-else statements in a do-while? Thanks! if (UserEmail.contains("#")) { if (UserEmail.contains(".edu")){ System.out.print("Please create a password: "); PassWord = kb.nextLine(); System.out.println(UserEmail.replaceAll("#\\S+?\\.edu\\b", "")); System.out.print("Your password is " + PassWord); } else { System.out.print("email is not valid Please, try again.") } else { System.out.print("email is not valid Please, try again."); // at this point it should repeat and ask for the email again } }
Define method isValid(String email, String password,... some more params) aand put all your check logic in the method. Write something like this while (!isValid(the params)) { //ask all the credentials }
to simplify your if-else code consider using if (UserEmail.contains("#") && UserEmail.contains(".edu")) { . . } this can be wrappped in a do - while do { if (UserEmail.contains("#") && UserEmail.contains(".edu")) { . . break; } System.out.print("email is not valid Please, try again.") } while (true);
You can simply add something like boolean correctEmail = false before your logic and at the beginning of your if statements, you write while(!correctEmail) { At the end of your password-creation you set correctEmail to true and you're ready to go.
It is pretty straight forward. bool trigger = (true/false); do { if (...) { if (...){...} else if (...) {...} else { print out retry statement; trigger = false; } } } while (trigger == true); Don't forget a semicolon at the end.