Browsing 7239 questions and answers with Jon Skeet

IllegalMonitorStateException Java Android

Runnable runner = new Runnable() { @Override public void run() { Movie m = adapter.getItem(id); m.setTitle(title); View v =...
Jon Skeet
people
quotationmark

I don't know why. You didn't provide a stack trace, but I assume it's on the call to this.notify(). From the documentation of Object.notify(): Throws: IllegalMonitorStateException - if the current thread is not the owner of... more 6/6/2014 9:46:32 AM

people

how to write result with label.text

I'm trying to add 2 numbers and then show the result. BUT NOT with Response.Write(result); as I can't place it where I want. I have this in my aspx: <asp:TextBox...
Jon Skeet
people
quotationmark

Currently you're calling plus, but ignoring the result. I suspect you want something like: Label_plus.Text = plus(tal1, tal2).ToString(); That sets the content of the label which will then be rendered within the response. Not sure if... more 6/6/2014 9:08:05 AM

people

Xamarin.Android JSON.Net serilization fails on 4.2.2 device only TimeZoneNotFound exception

I am using JSON.Net to serialize a DTO and I am getting the following exception on the physical device. THis works on all other devices we have tested on, but is failing on the...
Jon Skeet
people
quotationmark

Yes, TimeZoneInfo.Local is somewhat broken on Mono. I've seen three different failure modes here: Returning a time zone which acts correctly, but has an ID of "Local" Returning a null reference Throwing an exception I don't have a good... more 6/6/2014 6:09:35 AM

people

Unexpected java charAt output

The code is String veggie = "eggplant"; int length = veggie.length(); char zeroeth = veggie.charAt(0); char third = veggie.charAt(4); String caps =...
Jon Skeet
people
quotationmark

The second line should actually be: e l 8 (note that the second value is a lower-case L, not a 1) which probably doesn't violate your expections. Although your variable is confusingly called third despite it being the fifth character in... more 6/5/2014 6:11:42 PM

people

C# Variance Issue with IEnumerable<T> vs <T>

So, I'm having an issue with similar code to below: public static String MyFunc<T>(this IEnumerable<T> list) where T : struct { ... some code ... return...
Jon Skeet
people
quotationmark

The reason that it's currently picking the second method is that a conversion from a type to itself (second method, T=List<int>, conversion from List<int> to List<int>) will always be "better" than a conversion to the... more 6/5/2014 5:52:42 PM

people

NoClassDefFoundError when trying to parse JSON with JSON simple

I use JSON simple to parse JSON and I get NoClassDefFoundError when trying to create JSONParser object. import org.json.simple.JSONObject; import...
Jon Skeet
people
quotationmark

You're not including the Simple JSON jar file in your classpath when running. You want: // Unix java -cp .:json-simple-1.1.1.jar MyProgram // Windows java -cp .;json-simple-1.1.1.jar MyProgram (The : or ; is the path separator for the... more 6/5/2014 4:42:36 PM

people

Check class type

How i can check if a class is of a determinated type for example: // PacketHandler.java public interface PacketHandler<T> { public void handlePacket(T packet); } //...
Jon Skeet
people
quotationmark

Unfortunately Java generics use type erasure, meaning that at execution time, any particular PacketHandler<T> is just PacketHandler as far as the VM is concerned. You may want to change your code to: public interface PacketHandler... more 6/5/2014 4:32:00 PM

people

how to slice a doubles array in c#

I have a simple problem, but I am having a hard time getting the concept. I have an array of doubles (doublesarray) and I want to slice the array so that I get the last "x"...
Jon Skeet
people
quotationmark

Yes, the code you've shown already handles a negative end: if (end < 0) { end = source.Length + end; } So all you've got to do is the same thing for start: if (start < 0) { start = source.Length + start; } (Or use +=,... more 6/5/2014 4:09:11 PM

people

Java socket write byte[] instead of String

I'm new to socket programming, and I've been following several tutorials like this one http://www.myandroidsolutions.com/2012/07/20/android-tcp-connection-tutorial/ and was able...
Jon Skeet
people
quotationmark

You should use an OutputStream to write and an InputStream to read. Those are for binary data - anything with a suffix of Writer or Reader is for text data. You may find DataOutputStream and DataInputStream useful - they basically add... more 6/5/2014 1:07:06 PM

people

Is it possible to batch initialize regular variables in Java?

Is it possible to batch initialize some regular variables in Java in a loop? Here 'regular' means those variables are initialized alike. E.g Button btn1; Button btn2; Button...
Jon Skeet
people
quotationmark

The simplest approach would just be to create a method to do that: private Button createButton(String text) { Button ret = new Button(parentComposite, SWT.CHECK); ret.setText(text); ret.setSelection(true); ... more 6/5/2014 10:19:42 AM

people