Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Here is the piece of code
List<String> list = new ArrayList<String>();
list.add("Monkey");
Eclipse says:
Multiple markers at this line
Syntax error on token(s), misplaced construct(s)
Syntax error on token ""Monkey"", delete this token
I wasted about an hour trying to understand what is wrong.
This situation makes me hate java.
Most likely you have placed your code outside of a method or class. Try the following:
import java.util.ArrayList;
import java.util.List;
public class Test {
public Test() {
List<String> list = new ArrayList<String>();
list.add("Monkey");
}
}
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 1 year ago.
Improve this question
C:\Users>javaC C:\Main.java
C:\Main.java:1: error: error while writing Main: C:\Main.class
public class Main {
^
1 error
The error indicates that javac cannot create the compilation output C:\Main.class.
By default, a normal user does not have write access to the root of the C: drive. Create your class elsewhere (not directly in C:\), but for example in C:\development.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
String[] arraylist = {"0","0","0","0","0","0","0"};
but now I want to replace inside the array above to 1, to make it like this
String[] arraylist = {"0","0","0","1","0","0","0"};
Once try follow if you know position you want to change
arraylist[3]="1";
Hope this will helps you.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How to use it and an example with that please. Thanks! If you could also, I want a program that prints an array. I can't do it beaucause it makes me an error, and I want to know if I do something wrong.
Is that code right??
import java.util.Arrays;
kk
I get this:
I
I
[[I#e53108, [I#f62373]I
I
[[I#e53108, [I#f62373]
Osama, when I run your code, there pop ups an error box which says java exception and prints many errors.
Osama, your code when I run it says java Exception in an error box
I get this: I I [[I#e53108, [I#f62373]I I [[I#e53108, [I#f62373]
This is because you are printing a multi-dimensional array. For this, you can use Arrays#deepToString():
System.out.print(Arrays.deepToString(a));
A simple program to print an Array of string values
public class PrintArray{
public static void main(String[] args){
String[] array = {"a","b","c","d"};
for(String s : array)
System.out.println(s);
}
}
the output:-
a
b
c
d
I hope it's useful for you.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to translate a chess application that I had made in cpp, to java.
In my cpp version I had a structure which created a tree of strings.
Note, it was not a binary tree.
It was a vector of pointers, so from each node I had multiple subnodes stemming from it.
Does any one know how I could create a similar class in java?
public class ChessObject() {
private String description;
private List<ChessObject> subChessObjects;
}
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
Still getting the red bar. What's wrong with the AssertEquals?
public void testFindEmployeeByID() {
StubEmployeeRepositoryImpl result = new StubEmployeeRepositoryImpl(dataSource);
List<Employee> emp = result.findEmployeesByName("John", "X");
assertEquals("John"+"X", result.findEmployeesByName("John", "X"));
}
Probably assertEquals doesn't know how to compare List and String...