Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I want to create Color objects from Strings like "#b66c61" and"#33b7c4".
This is my code:
import android.graphics.Color;
......
String color_string = "#b66c61";
int color_int = Integer.parseInt(color_string.substring(1, color_string.length()-1));
Color color = Color.valueOf(color_int);
when I run it, I get the errer: Cannot resolve method valueOf(int)
although I'm sure the method exists : https://developer.android.com/reference/android/graphics/Color.html
any help?
You just have to use parseColor. see below -
String color_string = "#b66c61";
int myColor = Color.parseColor(color_string)
// use int color to set Color
myLayout.setBackgroundColor(myColor);
The method valueOf has been introduced in Android from API 26 onwards only. So it won't be available in other APIs and also there is no support library out there yet for 26. Thee exact use of this method would be illustrated only when things get out more clearly after the launch.
Check this
you can use
public static int parseColor (String colorString)
like this
String color_string = "#b66c61";
int color = Color.parseColor(color_string);
From Android documentation:
Supported formats are: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray'
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I know that it may be a silly mistake but I am looking at this code for about 15 minutes and I cannot see nothing wrong. Besides I can continue to do my work with this error.
I have the following method
GetMapping("/pagina/imoveis-residenciais-venda")
------------------------------------------------- (red marker of error)
public List<Imovel> recuperarPaginaImoveisResidenciaisVenda(){
List<Imovel> imoveis = this.imovelRepositorio.recuperarPaginaImoveisResidenciaisVenda();
return imoveis;
}
And the following error message, as GetMapping is underlined with the red marker:
invalid method declaration, required return type
GetMapping is an annotation, and annotation must start with an # sign so your code should look like this
#GetMapping("/pagina/imoveis-residenciais-venda")
public List<Imovel> recuperarPaginaImoveisResidenciaisVenda(){
List<Imovel> imoveis = this.imovelRepositorio.recuperarPaginaImoveisResidenciaisVenda();
return imoveis;
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
In the code below, the method onOrOff() must be printed to the console, stating engine is off. However, this specific method will not print.
I have tried System.out.println("engine is off");, but an error occurs stating “missing return statement”.
What is the main reason why the method onOrOff() is not shown in the output?
public static void main(String[] args) {
Vehicle truck = new Vehicle(200, 8, "red", 5);
System.out.println(truck.size);
System.out.println(truck.wheels);
System.out.println(truck.color);
System.out.println(truck.numbofGears);
onOrOff();
}
Vehicle(int size, int wheels, String color, int numbofGears) {
this.size=size;
this.color=color;
this.wheels=14;
this.numbofGears=numbofGears;
}
static String onOrOff() {
return Engine is off;
}
Your onOrOff() method returns a String and you're calling this method from main, yet you're not doing anything with the returned String. Try the following:
System.out.println(onOrOff());
UnholySheep already answered the question; but I will try to add a bit more details:
Engine is off is not a string. Also you need to print the return value of the method.
Erratum: Nathan Hughes did too
use double quotes, like this: return "Engine is off";
If you want a String, you have to surround the word(s) with double quotation marks, for example: "Hello World", or Foo.
So, in your example, you will have to use return "Engine is off" instead; return Engine is off by itself won't work.
Unrelated question, but why in the Vehicule constructor, you have a wheels parameter, but you give the associated attribute another value (14) regardless of the parameter?
Is that only temporary?
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
When using Java, what is the difference between the two following assignments:
String upperCaseDataType = "myName";
string lowerCaseDataType = "myName";
Do the 2 mean the same at compile time, just like in C#?
Thanks very much for your help.
string is not a class or type in Java
No. string s = "myName"; is not legal Java, and will not compile. Also, those are assignments (not assertions).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
im trying format a date using Joda-Time v 2.8.2, all the similar answers i have found say to use a method forPattern(), but with the version I am using it tells me that there is no such method(), am I using it incorrectly? or is this method deprecated or something? if so, what method is it replaced with if any?
Relevant code:
static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
public String timeSince(String dateString) {
org.joda.time.format.DateTimeFormatter formatter =
new DateTimeFormat.forPattern(DATE_FORMAT);
Seconds secondsSince = Seconds.secondsBetween(DateTime.parse(dateString, formatter),
DateTime.now());
...
}
cannot find class “forPattern()” is one thing, and tells me that there is no such method() is a totally different thing.
What is actually happening is that new Class.Function() is a syntax error.
So, java got confused, it thinks you must be trying to invoke a constructor, so it is telling you that it cannot find the class that contains such a constructor.
Solution: drop the new.
forPattern is a static method. Remove the new keyword
DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_FORMAT);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I guess its a rather simple question but i just cant find my mistake.
int[] myIntArray = new int[20];
myIntArray[5] = 5;
int a = myIntArray[5];
TextIO.putf("arr[i]: d%",a );
The error I get is Illegal format string in TextIO.putf() method.
So I assume the value at the index 5 is not an int?
The error message says exactly what the problem is: your format string is wrong. You probably meant %d (or better yet, %d%n to add a newline).
The format string elements are in the form
%[modifiers]type
not
something%
Change d% to %d.