I am learning Java and trying to make a basic Android application with Android Studio. When I try to add a TableLayout to an XML page the project will no longer compile because of errors in R.java.
Here are the errors:
Error: identifier expected
Error: illegal start of type
Error: identifier expected
These errors are repeated three times. Here are the lines it occurs on in R.java:
public static final class id {
public static final int 1=0x7f0b0086;
public static final int 2=0x7f0b0087;
public static final int 3=0x7f0b0088;
I'm guessing it fails because 1, 2, and 3 are not valid variable names, but I cannot change anything about a Java build file.
I found that others with similar problems in R.java were able to solve it by cleaning and rebuilding the solution, but this did not work for me. It will compile during the clean, but will fail to compile if I try to run it after that.
It means that at some XML (like layout/*.xml) you have tags with ids with those names android:id="#+id/1"
Since numbers are not a valid java identifier you must change the values in the XML to a alphanumeric string such 'a' ...
The class R is a compilation of the identifiers from all resources into res their names will be a variable into R, so name accordlyng
I got this error for wrong nameing:
<string name="1ab">text</string>
Resource name must begin with character and it worked
<string name="ab">text</string>
So just check if you have any resource name with wrong character in all your resource file(string.xml, style.xml, attrs.xml) and folder(drawable, layout).
Note: A variable's name can be any legal identifier — an unlimited-length
sequence of Unicode letters and digits, beginning with a letter, the
dollar sign "$", or the underscore character "_".
Thank you.
Related
I have a Java class that mainly contains strings. It does not have a layout as it is neither a Fragment nor an Activity. It is more used as an auxilliary class. I would like to assign the String values in the class by using the Resource strings as I would like to automatically translate the Strings. Howvever, I can't access the string resources from Java. I use the following code:
static String more = getString(R.string.more);
And in the XML file I have the ressource:
<string name="more">More</string>
I get the error message
Cannot resolve method 'getString'
I also tried static String more = getContext().getString(R.string.more);
but I got the error message:
Cannot resolve method 'getContext'
Would anyone mind helping me on that? I'd appreciate every comment.
Update: I tried to use the answer from "MikaelM"
Resources.getSystem().getString(R.string.more)
However, I get an "exception in initializer error" and when I use the initial String again, I do not get this error. So I still can't get the String from the ressource. DO you have an idea what I can do? I'd appreciate every further comment.
So the error is caused by "Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f120038"
The strange thing is that the resource in fact exists (I checked this several times).
getString(R.string...
is not the same as
Resources.getSystem().getString(android.R.string...
Only the second variant you can use in the static context. Alas, you can get this way only system resources.
If you need to get your own resources, no one-line solution exists. Use https://stackoverflow.com/a/4391811/715269 solution of #Cristian. And notice: it is a very good solution, even more, it is the solution meant to be used by the creators of Android.
You should be able to get your string with:
Resources.getSystem().getString(R.string.more)
See more here, getString Outside of a Context or Activity
I'm getting a "Conditionally Required Field Missing" error message, even though I'm sure that field is there.
58=Conditionally Required Field Missing, field=55
Versions:
QuickFixJ 2.1.0
FIX 4.4
Here is the FIX message that I'm sending (with mocked values and a few fields removed for clarity)
8=FIX.4.4
9=709
35=R
34=4
49=TARGET
56=ME
11=myClOrdID
131=myQuoteReqID
146=myNoRelatedSym
55=mySymbol // field missing
167=mySecurityType // field missing
Here is the calling code:
String symbol = quoteRequest.getField(new StringField(55)).getValue();
I also tried:
String symbol = quoteRequest.getString(55);
Here is my Data Dictionary:
<field number="55" name="Symbol" type="STRING"/>
I realize that the symbol field is no longer a part of the QuoteRequest FIX specification for 4.4 (though it was in earlier versions, such as 4.0), however surely there are ways to retrieve custom fields? I have no control over the QuoteRequest message that I receive.
I can always parse the message myself using toString() but that kinda defeats the purpose of using quickfixj in the first place.
Any ideas?
Tag 55 is inside the 146 repeating group. See the docs for reading repeating groups.
The symbol field is still in FIX44. You should spend some time familiarizing yourself with the FIX44.xml data dictionary file that you're using.
(You may find that you need to customize that file based on your counterparty's messaging; in practice, nobody uses the basic FIX44 message definitions without changing them at least a little.)
// create group
QuoteRequest.NoRelatedSym group = new QuoteRequest.NoRelatedSym();
// set group, confusing method name I find
message.getGroup(1, group);
// you now have all the getters of fields in that group
Symbol symbol = group.getSymbol();
I am using the Jenkins console sections plugin [1] on a windows server. It is excellent in order to make a nice left navbar on my logs.
Positively, I would like any error message to cause a section header, eg;
Assert-PathExstsNotTooLong : ERROR, The path does not exist: E:\P...
...
Oops! Error, please do not do that.
Negatively, I would like to be able to avoid having spelled-out execution templates cause a new section header, eg the below.
[workspace] $ cmd.exe /C " c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe /p:Configuration=Debug /p:VisualStudioVersion=12.0 "E:\Program Files (x86)\Jenkins\jobs\M.sln"
Using references here on SO [2] and on the tester you recommended [3], I came up with the following, but it is not working?
^(?=(.*([Ee][Rr][Rr][Oo][Rr] ).*))(?!(%%ERRORLEVEL%%))
Using Regex101's amazing tester, with JS flavor, I used the above as input and had these test strings and outputs. The second line of match info perhaps explains my issue but I do not understand it.
test-strings =
help error you should see me
i am %%errorlevel%% again
i am not a section
match-info;
1. `help error you should see me`
2. `error `
Any tips?
thank you!
1.[] ;This plugin uses Java Regex, per its docs ; ; ; ; X.Collapsing Console Sections Plugin - Jenkins - Jenkins Wiki ; ; https://wiki.jenkins-ci.org/display/JENKINS/Collapsing+Console+Sections+Plugin
2.[] ; An example regex on characters, not strings, to avoid; ; ; ; X.java - Regular expression include and exclude special characters - Stack Overflow ; ; Regular expression include and exclude special characters
3.[] ; ; ; ; ; X.Online regex tester and debugger: JavaScript, Python, PHP, and PCRE ; ; https://www.regex101.com/#javascript
(I can't add comments yet, otherwise I'd ask directly, but your example of a spelled-out message template doesn't include the text %%ERRORLEVEL%%, but I assume that it's meant to be a string with %%ERRORLEVEL%% somewhere in the middle of it. Also, as the example isn't quite right, I can't tell exactly what you mean by "not working")
Your problem is that your regex matches ERROR_ (with a space) anywhere in the text, except where the text is exactly %%ERRORLEVEL%%. I think that instead you could write:
^(?=(.*([Ee][Rr][Rr][Oo][Rr])))(?!.*(%%ERRORLEVEL%%)).*
Do you really need to only match ERROR_ (with a space) as opposed to ERROR (whether or not it has a space)? If the former, then you are already excluding %%ERRORLEVEL%%, and you could just use .*(?i:ERROR ).* as the full regex.
The Collapsing Console Sections Plugin uses Java regular expressions, so you can use (?i:ERROR) to match ERROR case-insensitively.
You need a trailing .* before and after your negative-lookahead atom for %%ERRORLEVEL%%, otherwise it will only exclude an exact match
The documentation for the plugin doesn't say whether the pattern has to match a line completely, or if it just matches text within the line. If it matches the line completely, the leading ^ is unnecessary, but won't be doing any harm.
You've got capturing brackets around ERROR and %%ERRORLEVEL%%. If you're not doing anything with that text, then those brackets are unnecessary.
The following regex will match any line with any of ERROR, Error, error etc in it, except lines with any of %%ERRORLEVEL%%, %%ErrorLevel%%, %%errorlevel%% etc.
^(?=.*(?i:ERROR))(?!.*(?i:%%ERRORLEVEL%%)).*
I'm very new to Android development (have some Obj-C experience with Cocoa Touch though). I was testing my first Android app as I encountered these syntax errors:
Syntax error on token "100000", invalid VariableDeclaratorId
Syntax error on token "11", delete this token
Syntax error on token "2", delete this token
Syntax error on token "5000", invalid VariableDeclaratorId
Syntax error on token "61", invalid VariableDeclaratorId
Syntax error on token "69", invalid VariableDeclaratorId
When I double clicked them, they appeared to be in the file R.java and I have no idea how they are caused.
public static final class drawable {
public static final int 100000=0x7f020000;
public static final int 11ba=0x7f020001;
public static final int 2values=0x7f020002;
public static final int 5000=0x7f020003;
public static final int 61=0x7f020004;
public static final int 69=0x7f020005;
.....
It would be great if someone can tell how this is caused.
[updates]
MarsAtomic suggested that it is caused by not following the naming conventions for Android resources and perhaps having rawables named "5000", "69", which is, as a matter of fact, true in this case.
After changing the names, these exceptions didn't occur anymore.
But I would still like to know why having images in numeral names would trigger this. Thanks.
My comment has disappeared somehow, but... every language has naming conventions. Conventions are often just based on some semi-arbitrary heuristic because you have to have rules (e.g. it's slightly more clear that 'a1' denotes a variable name, whereas a variable named '1' could be confused for a value).
You can accept this answer as the canonical answer or not -- personally, I'm not bothered who gets what credit.
After changing the names, this exceptions didn't occur anymore.
But I would still like to know why this is happening.
Because the names of those resources are used as field names in an auto-generated Java source file (R.java), and they aren't valid Java field names. Java field names must start with a letter. Details on the characters allowed in field names here in the JLS.
(Really, MarsAtomic should be getting the credit for this, but doesn't seem to have seen the reposted question.)
You cannot declare variable names starting with numbers.
R.class is auto-generated, if you change something in it,it won't work correctly.
Thy to Clean and Build your Project.
If you get an error in
public static final class drawable {
the most common mistake is a named .png file in your res folder starting with a number.
For example 1_pic.png, 2015_22_22pic.png and so on.
Right way: pic_1.png
Among all folders located inside \ res \ and look for a file with the name different from the others, as 00000002. If you find, just delete it. Then click the name of your project in eclipse and then press the F5 key to refresh it. Thus the error will disappear and your R file will be updated.
Take a look at the RES directories. You might have a file with the numerical sequence mentioned above, eg 00000002. To solve the problem, simply remove it from the folder.
I coded an enum type which brings up the following Syntax errors when I run my created JUnit test for it:
java.lang.Error: Unresolved compilation problems:
Syntax error, insert "enum Identifier" to complete EnumHeaderName
Syntax error, insert "EnumBody" to complete EnumDeclaration
Syntax error, insert "}" to complete ClassBody
My enum type has static functions which for a particular String, returns an enum constant. Here is some of my code of the enum type:
public enum MusicType {
ACCIDENTAL, LETTER, OCTAVE, REST, DUR, CHORD, TUPLET;
public static MusicType is_accidental(String a){
if (a=="^" | a=="_"|a=="=")
return ACCIDENTAL;
else return null;
}
}
The rest of my static functions are very similar (i.e. is_letter, is_octave, etc.), although some use input.matches(regex) function instead of checking to see if an input it equals a particular string.
Here is the beginning of the JUnit test which tests the function dealing with the accidental constant:
public class MusicTypeTest {
#Test
public void accidentalTest(){
String sharp = "^";
String flat = "_";
String natural = "=";
assertEquals(MusicType.ACCIDENTAL, MusicType.is_accidental(sharp));
assertEquals(MusicType.ACCIDENTAL, MusicType.is_accidental(flat));
assertEquals(MusicType.ACCIDENTAL, MusicType.is_accidental(natural));
}
}
The other functions in my JUnit test which test all the enum static functions are coded similarly. I cannot figure out why I have these syntax errors (this is my first time coding an enum type). I've been coding in Eclipse and have not found any missing "}"s as of yet. I don't know if this has anything to do with the way I've written the test or the way I've declared my variables. Does anyone know why I have these syntax errors?
I had this same problem with Eclipse. It was a misleading syntax error message. It was due to a misplaced ";" after an annotation.
Double check your code ignoring the message.
I was getting this error while writing an Android app. All my brackets were closed; I was following an example from a different site. I ended up selecting the entire text for my code, cutting, saving, and pasting the code back. The error went away. It's very possible that Eclipse got stuck...
Both the enum type and the class that you have just posted have two opening braces ({) and only one closing brace (}). If I had to guess, I'd say you need to put one more closing brace at the end of each of these files.