Browsing 7239 questions and answers with Jon Skeet
I am working on a application that extracts and moves files around to specific directories... At the same time deletes the files it used to extract, and etc etc etc. Just like a...
Currently, you're accessing the UI in the background worker, which you shouldn't - it's not running on the UI thread.
One overload of BackgroundWorker.RunWorkerAsync has an Object parameter, and this is the value that will available as...
more
11/24/2014 7:13:32 PM
I'm making a Life game and I made this method to find nearby neighbours
private int getNeighbours(LifeBoard board, int row, int col){
if(board.get(row+1, col)){
...
Well, you can use loops and just explicitly exclude the location itself (i.e. when the x and y offset are both 0):
private int getNeighbours(LifeBoard board, int row, int col) {
int neighbours = 0;
for (int xOffset = -1; xOffset...
more
11/24/2014 4:14:59 PM
I have this code and my problem is that it gives me an error in the methdod CrearProductoExtranjero in ProductoExtranjeroPe = new ProductoExtranjero(); that says that the...
Here are your two constructors:
public ProductoExtranjero(int PaisOrigen, String UnNombre, String UnRubro) {
super(UnNombre, UnRubro);
this.PaisOrigen = PaisOrigen;
}
public ProductoExtranjero(int PaísOrigen) {
...
more
11/24/2014 3:37:16 PM
Im calling a stored function like the following:
PreparedStatement deleteAll=connection.prepareStatement("{ call delete_all_data() }");
deleteAll.execute();
And in the logs i...
Change connection.prepareStatement (which expects SQL) to connection.prepareCall. That may very well be the only change you need, as a CallableStatement is a PreparedStatement.
more
11/24/2014 3:25:28 PM
I would have a async call to a function as following:
I'll call a method from the main method, this function should be async, how I do this?
A little example:
private static...
The simplest option would be to introduce a delay into your async method:
private static async void StartDoingNothingAsync()
{
await Task.Delay(1000);
// This will be called on a thread-pool thread
...
more
11/24/2014 8:30:17 AM
I have a question:
I have such a method in my JUnit Test case:
@Test
public void test1st_scenario() {
out = Mockito.mock(PrintStream.class);
System.setOut(out);
...
This is the problem, right at the start of your increaseExperience method:
restaurant = new Restaurant();
The restaurant you're working with in the method is entirely separate from the restaurant in the test.
Perhaps you should be...
more
11/24/2014 8:22:12 AM
So when i try
String string1 = "{"needs_reward":false,"has_voted":false,"sites":[{"id":3922,"name":"RuneTopList","has_voted":false,"vote_url":"http://api.runetoplist.com/vote/out?siteid=3922"},{"id":4613,"name":"RuneLocus","has_voted":false,"vote_url":"http://api.runetoplist.com/vote/out?siteid=4613"},{"id":4339,"name":"UltimatePrivateServers","has_voted":true,"vote_url":"http://api.runetoplist.com/vote/out?siteid=4339"},{"id":4340,"name":"TopG","has_voted":true,"vote_url":"http://api.runetoplist.com/vote/out?siteid=4340"},{"id":4341,"name":"MMORPGToplist","has_voted":true,"vote_url":"http://api.runetoplist.com/vote/out?siteid=4341"},{"id":4622,"name":"Rune-Server","has_voted":true,"vote_url":"http://api.runetoplist.com/vote/out?siteid=4622"},{"id":4623,"name":"GTop100","has_voted":true,"vote_url":"http://api.runetoplist.com/vote/out?siteid=4623"},{"id":4828,"name":"GamingTopList","has_voted":true,"vote_url":"http://api.runetoplist.com/vote/out?siteid=4828"},{"id":4829,"name":"RSPS-List","has_voted":true,"vote_url":"http://api.runetoplist.com/vote/out?siteid=4829"},{"id":4861,"name":"Top100Arena","has_voted":true,"vote_url":"http://api.runetoplist.com/vote/out?siteid=4861"}]}"
I get errors because it contains brackets, how would i set this as a string?
Thanks for the help.
The brackets aren't problem - the quotes are. For example, this is fine:
String braces = "{}";
The quote (") is used to terminate a string, so you need to escape it with a \:
String sentence = "My son said, \"Hello, world!\" and then...
more
11/24/2014 7:12:52 AM
I have a same class belonging to 2 different packages.
package x1.y1.Class
packgage x2.y2.Class
Is it possible that if I am invoking a x1.y1.Class via classloader, x2.y2.Class...
No, it can't happen, for two reasons:
The classloader finds the class by package, by looking in the right place
Even if you accidentally put a class in the wrong place, the class file itself includes the package name, and this is checked...
more
11/24/2014 6:52:17 AM
From page 291 of OCP Java SE 6 Programmer Practice Exams, question 25:
public class Stone implements Runnable {
static int id = 1;
public void run() {
id = 1 -...
Am I wrong?
Nope, you're absolutely right - as is your example timeline.
In addition to it not being atomic, it's not guaranteed that the write to id will be picked up by the other thread anyway, given that there's no synchronization...
more
11/23/2014 1:01:29 PM
my activity_main.xml file looks like this:
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
...
It looks to me as if you've pasted some text from Word or something similar, which means you've got "curly quotes". So your XML declaration looks like this:
<?xml version=”1.0” encoding=”utf-8” ?>
when it should be like...
more
11/23/2014 9:22:46 AM