Browsing 7239 questions and answers with Jon Skeet

Override Process Class in Java

I am new to java and I am doing this multithreaded application in Java Swing. I need to create a custom class which can spawn multiple threads and execute those threads at the...
Jon Skeet
people
quotationmark

Is it a good idea to use Process to spawn threads? No. That's designed to spawn processes, which are very different. You can either create threads directly with code such as new Thread(runnable).start(), or use an ExecutorService for... more 12/5/2013 12:12:55 PM

people

How to read specific amount of data from a large file

I have a 1GB file containing 1 string per line. I have to read the first 100MB such that if the boundary falls in the middle of the string, the whole of the last line gets...
Jon Skeet
people
quotationmark

One option is to use a StreamReader to read the lines, but check the Position on the underlying stream: List<string> lines = new List<string>(); using (var reader = File.OpenText("file.txt")) { string line; while... more 12/5/2013 8:11:20 AM

people

IEnumerable Best Practice of removing int item

I have a IEmunerable list with N items for example: 23, 1, 38..... The needed logic is, when looping thru the list: 1: find if 1exist 2: if 1 exist, find 2 3: if 2...
Jon Skeet
people
quotationmark

It's not clear why you're looping to start with, or using Any instead of Contains: if (someIntList.Contains(1) && someIntList.Contains(2) && someIntList.Contains(3)) { someIntList = someIntList.Where(x => x != 3);... more 12/5/2013 7:31:31 AM

people

Array Index Out of Bounds For Loop Print Contents ArrayList

// ArrayList import java.io.*; import java.util.*; public class ArrayListProgram { public static void main (String [] args) { Integer obj1 = new Integer (97); String obj2 =...
Jon Skeet
people
quotationmark

The problem is your stray semi-colon at the end of the for loop: for(i=0; i<objects.size(); i++); // Spot the semi-colon here { System.out.println(objects.get(i)); } That means your code is effectively: for(i=0;... more 12/5/2013 7:14:19 AM

people

Nesting string.splits in a for loop inner split gets NPE when assigned

So, today I hit a snag trying to split a string array element which has been split from a long string already.. It works like this: A string is created from a file. This string is...
Jon Skeet
people
quotationmark

It seems likely to me that Topics is null - there's nothing within the code you've shown to assign it a non-null value. You probably want: Topics = new String[lines]; before the loop. You should be able to spot this pretty easily in the... more 12/5/2013 6:50:39 AM

people

Delegate type Cannot convert anonymous method

getting error in following line "this.dgvReport.Invoke(delegate" "Cannot convert anonymous method to type 'System.Delegate' because it is not a delegate type" public...
Jon Skeet
people
quotationmark

The Invoke method has a parameter of type Delegate, and you can only convert an anonymous function to a specific delegate type. You either need to cast the expression, or (my preferred option) use a separate local variable: // Or... more 12/4/2013 7:25:05 AM

people

Remove Escape Sequence Not Working

I have HTML code like this: <tr> <th colspan="2" style="padding: 10px; font-size: 11px; background: #eee; border: 1px solid white" align="left"> Some...
Jon Skeet
people
quotationmark

But When I Debug It Show String Like this That's because you're looking at the string in the debugger. The string doesn't actually contain those backslashes - they're just part of the debug output, which escapes various characters to... more 12/4/2013 7:04:15 AM

people

Pass data between methods in C#

I have the following code in my windows 8 desktop app. This gets data from a web service and populates it in a List SampleDataGroup. protected override async void...
Jon Skeet
people
quotationmark

Well currently your async method returns void, and you're not doing anything with info after populating it. It seems to me that you probably want to either return that list from the method (making it return... more 12/4/2013 6:55:23 AM

people

Counter Invoked in Two ActionListeners

I have a counter x that I want to invoke in two separate ActionListeners. When I try to make x into final, I can't increment using x++;. I tried to make x within the nest, but...
Jon Skeet
people
quotationmark

One simple option is to use AtomicInteger instead - then the variable can be final, but you can still increment the wrapped value. So: final AtomicInteger counter = new AtomicInteger(0); buttonIn.addActionListener(new ActionListener() { ... more 12/4/2013 6:46:13 AM

people

Equivalent to Java's "restricted" and "extends" in C#?

EDIT: I apologize, I meant protected instead of restricted. I was tired. Is there an equivalent to Java's restricted and extends in C#? I can see that neither are in C#, and they...
Jon Skeet
people
quotationmark

It sounds like you probably want: using System; namespace CServer.API { public class Plugin { protected Plugin() { // This code will execute before the body of the constructor // in... more 12/3/2013 11:14:12 PM

people