Browsing 7239 questions and answers with Jon Skeet

Android: Getting a null value when assigning Button id

I am making a simple 3x3 grid type application that when I click a button, the last button clicked is " " and the button I just clicked is "!". However, I keep getting the...
Jon Skeet
people
quotationmark

I believe the problem is here: GameActivity game = new GameActivity(); public void updatePlayer(Button buttonID){ game.setPlayer(buttonID); } You're creating the GameActivity by calling the constructor directly, rather than it being... more 1/7/2015 9:01:11 PM

people

How do I convert a FileContentResult to a FileStreamResult?

I have a FileContentResult obtained from a byte array and want to turn it into a FileStreamResult. Is this possible? If so, how?
Jon Skeet
people
quotationmark

Firstly, I don't know much about MVC but it sounds like you shouldn't need to do this. If you have code which depends on FileStreamResult, see if you could make it depend on FileResult instead, which is the base class of both... more 1/7/2015 8:53:31 PM

people

How can I construct a class when the super class uses @Inject?

I have the following code: public abstract class AbstractClass<T> { final A a; @Inject AbstractClass(A a) { this.a = a; } } public class B extends...
Jon Skeet
people
quotationmark

You need to accept an A as well: @Inject B(A a, D d) { super(a); this.d = d; } Then Guice should inject both the A and the D, and you just pass the A up to the superclass constructor. Just because a constructor is marked with... more 1/6/2015 9:23:29 PM

people

Linq to XML Disable default namespace

I'm trying to use LINQ to XML to write queries for a WebDAV server but I'm having a problem where LINQ is setting a default namespace (xmlns = "bla") which doesn't seem to be...
Jon Skeet
people
quotationmark

The problem is that your element isn't in the DAV: namespace - it's in the d namespace. You need to differentiate between the namespace URI and the namespace alias. You want: XNamespace ns = "DAV:"; var content = new XElement(ns +... more 1/6/2015 6:59:52 PM

people

C# Directory.EnumerateFiles Wrong Ordering

I'm reading some files from a folder with : foreach (string file in Directory.EnumerateFiles(<folder>, "Client_*.txt")) { //Do my stuff } If I have the files...
Jon Skeet
people
quotationmark

If the files are always of the form Client_<number>.txt then you basically want to sort them according to the parsed number. So write a method to take the original filename, take off the prefix/suffix (or extract the digits with a... more 1/6/2015 6:28:55 PM

people

How to properly access the value of a capture group in C# regex?

I have the following code: using System; using System.Text.RegularExpressions; public class Test { public static void Main() { var r = new Regex(@"_(\d+)$"); ...
Jon Skeet
people
quotationmark

You're getting the value of the whole Match - you only want a single group (group 1) which you can access via the Groups property and the GroupCollection indexer: Console.WriteLine(match.Groups[1]); more 1/6/2015 4:06:10 PM

people

Compare float in ArrayList

I have this : Offers eoResponse = eoClient.getOffers(url); Collections.sort(eoResponse, new Comparator<Offer>() { public int compare(Offer offer1, Offer offer2) { ...
Jon Skeet
people
quotationmark

It sounds like you probably want: return Float.compare(offer1.getAmount(), offer2.getAmount()); That's if getAmount() returns a float - that means you won't be able to call methods on it directly, but Float.compare is a handy... more 1/6/2015 2:23:02 PM

people

Reading resource txt line by line

Had a txt file on my desktop with code: string source = @"C:\Users\Myname\Desktop\file.txt" string searchfor = *criteria person enters* foreach (string content in...
Jon Skeet
people
quotationmark

You can use a TextReader to read a line at a time - and StreamReader is a TextReader which reads from a stream. So: var assm = Assembly.GetExecutingAssembly(); using (var stream =... more 1/6/2015 2:06:50 PM

people

Cannot resolve method getlatitude()

I am new to programming and am following the Google Location API tutorial. I have followed all the steps properly, however, the following code gives me error at getlatitude() and...
Jon Skeet
people
quotationmark

Look at the type of mLastLocation: protected String mLastLocation; String doesn't have getLatitude and getLongitude methods. Your variable should be of type Location, and initialized without the String.valueOf call: protected Location... more 1/6/2015 1:28:38 PM

people

How to access Interface method implemented in the derived class from child class?

I have two interfaces A,B both has same method declarations. I have a class C inheriting from interfaces A,B. I have another class D inheriting from C. Now i want to access the ...
Jon Skeet
people
quotationmark

How to access the methods in C from D? You have to use a reference with a compile-time of the relevant interface. For example: class D { public void FooA() { A a = this; Console.WriteLine(a.mul(...)); } ... more 1/6/2015 10:53:18 AM

people