Browsing 7239 questions and answers with Jon Skeet

Java clock error

I was making a clock, which displays time in Java, I will show the code below: public class MyApp extends javax.swing.JFrame { int timeRun = 0; /** * Creates...
Jon Skeet
people
quotationmark

You've created a thread, but you haven't overridden the run method - instead you've created a Run method. Java is case-sensitive. Change this: public void Run() { ... } to this: @Override public void run() { ... } Using... more 11/20/2013 12:59:54 AM

people

Count number of lines in text skipping the empty ones

I need help with this. Can you tell me how to calculate the number of lines in the input.txt without counting the empty space lines? So far, I tried: BufferedReader reader...
Jon Skeet
people
quotationmark

You just need to remember the line you're looking at, and check it before counting: int lines = 0; String line; while ((line = reader.readLine()) != null) { if (!line.isEmpty()) { lines++; } } Note that you should be... more 11/19/2013 11:00:08 PM

people

Cannot make non abstract subclass of abstract superclass?

I have a subclass that declares all of the methods in my abstract superclass, yet it still gives me an error stating that my class isn't abstract. I cannot figure out why this...
Jon Skeet
people
quotationmark

This is the problem: public int compareTo(PhoneNumber other) { super.compareTo(other); } You've specified that you're just implementing the raw type Comparable, which has a method with a signature of: int compareTo(Object) The... more 11/19/2013 10:26:40 PM

people

Generic hashtable method doesn't work correctly in C#

I am trying to implement a hashtable in C#. Here's what I have so far: using System; using System.Collections.Generic; using System.Linq; using System.Text; using...
Jon Skeet
people
quotationmark

This is the problem, in your Add method: array.Insert(index, ToAdd); Your array variable isn't actually an array - it's a list. And you're inserting elements into it, rather than just setting the existing element. That will affect all... more 11/19/2013 9:11:36 PM

people

Coverting MySQl 'YYYY MM DD' to .Net DateTimePicker

How can I read Default Mysql Date 'YYYY-MM-DD' using Datareader and convert it into .Net c# DatetimePicker. In Short I want to see my date entered into MySQL visually selected on...
Jon Skeet
people
quotationmark

Don't read it as a string at all. Use the GetDateTime method on the reader to read it as a DateTime, and then you can specify that as the value of the DateTimePicker. It's worth avoiding string conversions wherever possible, in my opinion... more 11/19/2013 5:46:52 PM

people

Getting a byte array instead of saving a byte array as a file

I'm getting a raw varbinary data from an SQL server. Firstly I'm saving it as a file, because I am loading the file and drawing a series of points on a chart. But now I also want...
Jon Skeet
people
quotationmark

It sounds like you should just be writing to a MemoryStream: var stream = new MemoryStream(); var buffer = new byte[8 * 1024]; long bytesRead; long index = 0; while ((bytesRead = reader.GetBytes(1, index, buffer, 0, buffer.Length)) >... more 11/19/2013 5:10:32 PM

people

How to avoid xmlns="" in an XML element added?

I have 287 SSRS reports (XML files), where I need to add a parameter. They all start like this: <?xml version="1.0" encoding="utf-8"?> <Report...
Jon Skeet
people
quotationmark

How can I avoid the empty xmlns attribute ? Create the elements in the right namespace. Due to namespace defaulting, all your elements should be in the http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition... more 11/19/2013 2:55:26 PM

people

Acceptable to use a Type for a Dictionary Key?

I would like to make a class that can store at most one copy of an object. All the objects stored here will share the same base class, and I would like to be able to get an object...
Jon Skeet
people
quotationmark

There's one issue: it's not thread-safe. Given that you appear to be using this via a singleton, I'd imagine you do need it to be thread-safe. If you're using .NET 4, you'd be best off using ConcurrentDictionary. Otherwise, add... more 11/19/2013 2:11:41 PM

people

Java Runtime errors

Please anyone Help me in solving this error Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: schemes cannot be resolved to a...
Jon Skeet
people
quotationmark

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: schemes cannot be resolved to a variable schemes cannot be resolved schemes cannot be resolved schemes cannot be resolved to a variable This... more 11/19/2013 12:56:15 PM

people

IQueryable<a> to list<b> type conversion, when a & b having similar signature using LINQ

I'm having some basic problem with linq, I tried to google but didn't get the desired reuslt. Lets say We have two class with almost similar signature like these: public class...
Jon Skeet
people
quotationmark

You need to use Select to project from one type to another, then ToList to create a list: // Property names changed to follow .NET naming conventions var list = query.Select(a => new B { X = a.A, Y = b.B, Z = c.C }) ... more 11/19/2013 4:51:04 AM

people