Browsing 7239 questions and answers with Jon Skeet

java Line breaks not working

I'm writing a simple program that writes data to the selected file . everything is going great except the line breaks \n the string is written in the file but without line breaks ...
Jon Skeet
people
quotationmark

My guess is that you're using Windows. Write \r\n instead of \n\r - as \r\n is the linebreak on Windows. I'm sure you'll find that the characters you're writing into the file are there - but you need to understand that different platforms... more 11/5/2013 7:24:22 PM

people

Where clause in list of class inside another class using Lambda expression in C#

I have the class "Group" and inside this class I have a colletion of class "User" public partial class Group { public Group() { this.User= new...
Jon Skeet
people
quotationmark

If you're trying to get groups where any users are active, you want: var groups = Groups.Where(g => g.Users.Any(u => u.Active)); If you want groups where all the users are active, you want: var groups = Groups.Where(g =>... more 11/5/2013 6:16:58 PM

people

If I declare a variable in a java method, is that variable also accessible to any method called from the method in which it is declared?

If I declare a variable in a java method, is that variable also accessible to any method called from the method in which it is declared? When I try the following, function2 does...
Jon Skeet
people
quotationmark

When I try the following, function2 does not recognise the variable variable1. Should this be the case? Yes. It's a local variable - local to the method in which it's declared. That method could be executing several times within the... more 11/5/2013 5:45:00 PM

people

Why is my Sqlite table doubling it's self?

My Sqlite table should have 50 rows. When I run the program for the first time, and go to check the table through firefox viewer, I see 50 rows (as it should be). When I run the...
Jon Skeet
people
quotationmark

When I run the program for a second time and check the table, it's rows double - i,e it now has 100 rows. Well yes, it would. You've said to create the table if it doesn't exist, and then you're inserting a bunch of data, without... more 11/5/2013 4:19:55 PM

people

Use builder pattern for methods with many parameters?

I've read a recommendation in "Effective Java" to use the Builder pattern when faced with constructors that use lots of parameters. Does the same pattern apply to methods with...
Jon Skeet
people
quotationmark

Yes, sort of. You basically create a new type to encapsulate all the parameters - or maybe just some of them. Now you can create a builder and then an immutable version of the type - or you could just allow the "uber-parameter" type to be... more 11/5/2013 4:11:16 PM

people

Through get Method, Getting Acces to Other Classes Variables

I am trying to access variable from one class to another. I tried help from this question but it was on other way. I have a base class as following: public class BasePage :...
Jon Skeet
people
quotationmark

You haven't created a customerId property. You've created a MemberUserId property. That said, your code would still be invalid as you've declared the basePage local variable, but haven't assigned a value to it. Are you sure you don't just... more 11/5/2013 1:32:19 PM

people

Investigate the 8 fields arround every field in two dimensional array?

How to check the 8 neighbours of the field? I mean some fields have just 3 neighbours, because they are on the border of the array. thanks for help
Jon Skeet
people
quotationmark

Yes, so you need to take account of that by checking for the row and column values being 0 or the height/width. If you're just adding up values, you may find it easiest to have a method which just returns the value in the array, or 0 if... more 11/5/2013 8:03:30 AM

people

Convert byte array to int32

I have a problem to convert byte array to int32 via BitConverter.ToInt32. An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll Additional...
Jon Skeet
people
quotationmark

Presumably the UTF-8 representation of the text in textBox2 is fewer than 4 bytes long. BitConverter.ToInt32 requires 4 bytes of data to work with. It's not clear what you're trying to achieve, by the way - but using BitConverter.ToInt32... more 11/5/2013 7:56:50 AM

people

How to send a hardcoded datetime value as input to stored procedure?

This may sound easy but I've tried several times yet couldn't get what I want. I have a stored procedure that has an input which is of DATETIME type. I've made sure the stored...
Jon Skeet
people
quotationmark

(Answer written before the restriction against parameterized SQL was added.) How should I specify the value of Datetime? With parameterized SQL, just like other values. using (SqlCommand command = new SqlCommand("StoredProcName",... more 11/5/2013 7:26:23 AM

people

Using the extended class constructor

I was wondering if it was possible to do the following with a Class, that extends another class in Java, if so. How?: public class HelloWorld { public HelloWorld() { ...
Jon Skeet
people
quotationmark

Your A constructor needs to chain to a B constructor using super. At the moment the only constructor in B takes an int parameters, so you need to specify one, e.g. public A(int x) { super(x); // Calls the B(number) constructor ... more 11/4/2013 5:22:51 PM

people