Browsing 7239 questions and answers with Jon Skeet

My program cannot break out of 'While Loop' when calculating # of divisors for a certain integer?

When I run the program in eclipse, I cannot break out of the while loop after the user enters a certain integer to move on and actually calculate the number of divisors it has and...
Jon Skeet
people
quotationmark

Look at your if statement: if (N < 0) break; You're breaking out of the loop if the user enters a negative number - but you want to break out if they enter a positive number: if (N > 0) break; (I haven't looked at the... more 12/28/2013 8:22:19 AM

people

Using NodaTime, how to convert an Instant to the corresponding system's ZonedDateTime?

I have an event log in a database with the events' datetime stored as UTC time. In my application, where I'm using NodaTime, I get the value as a DateTime and then convert it to...
Jon Skeet
people
quotationmark

Use IDateTimeZoneProvider.GetSystemDefault for the time zone provider you're interested in. For example: var systemZone = DateTimeZoneProviders.Tzdb.GetSystemDefault(); var zonedDateTime = instant.InZone(systemZone); Or use... more 12/27/2013 9:05:45 PM

people

C# Date/Time Formatting

Using C#, I am trying to format a date in to the following string format: YYYYMMDD_HHMM.xlsx Here is my code: DateTime.Today.AddDays(0).ToString("yyyymmdd") + "_" +...
Jon Skeet
people
quotationmark

You're using mm, which is minutes, not months - and you're trying to print the time using DateTime.Today, which always returns midnight at the start of the day. It's not clear why you're adding 0 days, either. I'd use: DateTime now =... more 12/27/2013 8:27:52 PM

people

Accessing sub array and counting an element in arrays in Java

I have 2 questions about arrays in java and any help would be appreciated. Is there a way to access a sub-array (something like this on python: array[1:5]) I want to know does...
Jon Skeet
people
quotationmark

For accessing part of an array, you could use Arrays.asList to obtain a List<E>, and then use the subList method to obtain a slice: import java.util.*; public class Test { public static void main(String[] args) { ... more 12/27/2013 12:16:42 PM

people

How to cast object to Action<T>

I've created a simple message bus that queues and emits/publishes events. I'm using StructureMap to locate the registered handlers (Action<T>) of the event but am not sure...
Jon Skeet
people
quotationmark

Since I can't cast to Action I'm assuming that Action is not covariant? Action<T> is contravariant - which makes sense, because an Action<object> can be treated as an Action<string> (both can accept a string... more 12/27/2013 11:42:44 AM

people

How to get the string instance in guice

Lets say I have binded my strings in guice like this bind(String.class).annotatedWith(MasterDatabase.class).toInstance("integration"); If I have the handler to injector for...
Jon Skeet
people
quotationmark

Well you'd normally use constructor injection using the annotation: @Inject public SomeType(@MasterDatabase String databaseName) Or you could explicitly request it from the injector: String databaseName =... more 12/27/2013 11:34:01 AM

people

A child container failed during start java.util.concurrent.ExecutionException:

hi i am trying to run JAX-RS Web Service project which contain sample hello world web service, but publishing it in the Tomcat Server 7.0 shows following errors. Below are...
Jon Skeet
people
quotationmark

Well this is the root cause: Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function ... so it looks like you're probably missing a dependency jar file (Guava, by the looks of it) from the classpath of the relevant... more 12/27/2013 9:00:03 AM

people

set limit to number of children in an element in xml

I have an XML file as follows <abc> <property> <Recentlyopenedfiles> <File Path="c:\hai.txt" /> <File Path="C:\old.java" /> ...
Jon Skeet
people
quotationmark

There are declarations in XSD to limit the number of child elements, but I don't think that's relevant in your particular case. When it comes to parsing and then modifying the XML, you'll just need to perform the limiting by hand. In... more 12/27/2013 8:58:14 AM

people

Dollar ($) sign after activity class name in Android logs (non anonymous inner class)

I am going through some crash logs for my app and the stack trace shows something like : at MyActivity.formatDouble(MyActivity.java:182) at...
Jon Skeet
people
quotationmark

I suspect that line 167 is within an anonymous class within MyActivity, and that access$47 is simply a trampoline method to allow onCameraChange to call a private method within MyActivity. (The JVM wouldn't allow that, so the Java compiler... more 12/26/2013 9:23:36 PM

people

clarification needed on Java's 32 bit integer representation system?

I need some clarifications regarding the binary representation of decimal in Java (or any other language for that matter). pardon, if this is too basic, but I need to understand...
Jon Skeet
people
quotationmark

so it means, the when 31 bits are turned on, I do not get the additive sum of the powers of 2. Yes you do - you get 20 + 21 + 22 + 23 + ... + 230... which is 231 - 1, exactly as you're seeing. You're not adding 231 because that would... more 12/26/2013 8:36:16 PM

people