From phil at rephil.org Sun Mar 3 12:41:32 2002 From: phil at rephil.org (Phil Mendelsohn) Date: Mon Jan 17 14:29:33 2005 Subject: [TCLUG-DEVEL] Java detail Message-ID: <20020303184132.GA10054@rephil.org> Hi, I'm picking up some Java on the fly, and am making what is probably a simple oversight type of error. Could someone tell me why I'm having trouble accessing arrays of objects in an object from a class's member functions? Here is the beginning of the class, with the constructors. It's a little messy -- there's been some initialization code added for debugging. The constructor seems to work fine, but though it compiles, when I call it in another program (some test code) it just hangs as soon as it tries to read or write values in the arrays. I've been liberal with the 'public' statements; the reason (debugging / desperation!) should be clear, and is not an issue for what I'm doing. This is a U homework thing, but it's not a Java class (it's Algorithms), so no fear about academic integrity in answering. Help is appreciated! Phil Mendelsohn -- www.rephil.org "Trying to do something with your life is like sitting down to eat a moose." --Douglas Wood ----------- public class PriorityQueue{ public qItem [] Q; public int qSize; public int [] where; public class qItem{ public int item; public int key; public qItem(int item, int key){ //consructor this.item = item; this.key = key; } } public PriorityQueue(int maxItem){ //constructor of an empty queue: see below qItem [] Q = new qItem[maxItem]; int [] where = new int[maxItem]; for( int j=0; j < maxItem; j++){ where[j] = -1; Q[j] = new qItem(-2, -3); System.out.println(where[j] + " " + Q[j].item + " " + Q[j].key); } int qSize = 0; }//end constructor void insert(int item, int key){ //insert the item with given key as its priority qSize++; System.out.println("qSize: " + qSize); System.out.println("Item: " + item); System.out.println("Key: " + key); for(int i = 0; i < qSize; i++){ System.out.println(Q[i].item); System.out.println(Q[i].key); } } From lamfada at lugh.net Sun Mar 3 13:24:43 2002 From: lamfada at lugh.net (Chris McKinley) Date: Mon Jan 17 14:29:33 2005 Subject: [TCLUG-DEVEL] Java detail In-Reply-To: <20020303184132.GA10054@rephil.org> Message-ID: 1) Nothing is ever inserted into the queue. 2) Queues usually have push()/pop() methods which insert/remove elements. The element at the front is usually accessed with a front() method. 3) Instead of pre-allocating an Array, you may wish to use a Vector for priority, or in this case, a TreeMap may be ideal. A TreeMap implements SortedMap, and guarantees that the keys and values of the mapping can be enumerated in ascending order of keys. The issue with this is that the get() method returns an Object, which you have to cast to the correct type. You will need to use Integers instead of ints. If the assignment disallows use of Java's collections, then disregard this. 4) I don't understand the use of 2 arrays. what is the where[] array for? 5) Your primary problem here is this: scoping. Take a look at your constructor for scoping issues. Is a definition hiding another definition? Good luck. -Chris McKinley finger lamfada@lugh.net for GPG key On Sun, 3 Mar 2002, Phil Mendelsohn wrote: > Hi, > > I'm picking up some Java on the fly, and am making what is probably a > simple oversight type of error. Could someone tell me why I'm having > trouble accessing arrays of objects in an object from a class's member > functions? > > Here is the beginning of the class, with the constructors. It's a > little messy -- there's been some initialization code added for > debugging. The constructor seems to work fine, but though it > compiles, when I call it in another program (some test code) it just > hangs as soon as it tries to read or write values in the arrays. > > I've been liberal with the 'public' statements; the reason (debugging > / desperation!) should be clear, and is not an issue for what I'm > doing. This is a U homework thing, but it's not a Java class (it's > Algorithms), so no fear about academic integrity in answering. > > Help is appreciated! > > Phil Mendelsohn > > -- > www.rephil.org > > "Trying to do something with your life is like > sitting down to eat a moose." --Douglas Wood > > ----------- > > public class PriorityQueue{ > > public qItem [] Q; > public int qSize; > public int [] where; > > public class qItem{ > public int item; > public int key; > > public qItem(int item, int key){ > //consructor > this.item = item; > this.key = key; > } > } > > > public PriorityQueue(int maxItem){ > //constructor of an empty queue: see below > qItem [] Q = new qItem[maxItem]; > int [] where = new int[maxItem]; > for( int j=0; j < maxItem; j++){ > where[j] = -1; > Q[j] = new qItem(-2, -3); > System.out.println(where[j] + " " + Q[j].item + > " " + Q[j].key); > } > int qSize = 0; > }//end constructor > > > void insert(int item, int key){ > //insert the item with given key as its priority > qSize++; > System.out.println("qSize: " + qSize); > System.out.println("Item: " + item); > System.out.println("Key: " + key); > for(int i = 0; i < qSize; i++){ > System.out.println(Q[i].item); > System.out.println(Q[i].key); > } > } > _______________________________________________ > tclug-devel mailing list > tclug-devel@mn-linux.org > https://mailman.mn-linux.org/mailman/listinfo/tclug-devel > From dutchman at uswest.net Sun Mar 3 14:26:57 2002 From: dutchman at uswest.net (Perry Hoekstra) Date: Mon Jan 17 14:29:34 2005 Subject: [TCLUG-DEVEL] Java detail References: <20020303184132.GA10054@rephil.org> Message-ID: <3C828710.99D8D12C@mn.uswest.net> Phil Mendelsohn wrote: > Hi, > > I'm picking up some Java on the fly, and am making what is probably a > simple oversight type of error. Could someone tell me why I'm having > trouble accessing arrays of objects in an object from a class's member > functions? > > Here is the beginning of the class, with the constructors. It's a > little messy -- there's been some initialization code added for > debugging. The constructor seems to work fine, but though it > compiles, when I call it in another program (some test code) it just > hangs as soon as it tries to read or write values in the arrays. > > I've been liberal with the 'public' statements; the reason (debugging > / desperation!) should be clear, and is not an issue for what I'm > doing. This is a U homework thing, but it's not a Java class (it's > Algorithms), so no fear about academic integrity in answering. > > Help is appreciated! > > Phil Mendelsohn > > -- > www.rephil.org > > "Trying to do something with your life is like > sitting down to eat a moose." --Douglas Wood > > ----------- > > public class PriorityQueue{ > > public qItem [] Q; > public int qSize; > public int [] where; > > public class qItem{ > public int item; > public int key; > > public qItem(int item, int key){ > //consructor > this.item = item; > this.key = key; > } > } > > public PriorityQueue(int maxItem){ > //constructor of an empty queue: see below > qItem [] Q = new qItem[maxItem]; > int [] where = new int[maxItem]; > for( int j=0; j < maxItem; j++){ > where[j] = -1; > Q[j] = new qItem(-2, -3); > System.out.println(where[j] + " " + Q[j].item + > " " + Q[j].key); > } > int qSize = 0; > }//end constructor > > void insert(int item, int key){ > //insert the item with given key as its priority > qSize++; > System.out.println("qSize: " + qSize); > System.out.println("Item: " + item); > System.out.println("Key: " + key); > for(int i = 0; i < qSize; i++){ > System.out.println(Q[i].item); > System.out.println(Q[i].key); > } > } By the way, you are missing a '}' at the end. A couple of questions, first is: aItem a inner class? Second, do you have a main method that you use for testing? The reason I ask is I am not quite sure what the class is supposed to do and a main/test method would help me walk through the processing. -- Perry Hoekstra E-Commerce Architect Talent Software Services perry.hoekstra@talentemail.com From dutchman at uswest.net Sun Mar 3 14:41:10 2002 From: dutchman at uswest.net (Perry Hoekstra) Date: Mon Jan 17 14:29:34 2005 Subject: [TCLUG-DEVEL] Java detail References: <20020303184132.GA10054@rephil.org> Message-ID: <3C828A65.D6FE45AF@mn.uswest.net> Phil Mendelsohn wrote: > public class PriorityQueue{ > > public qItem [] Q; You define Q here but give no value which means Q is null. > > public int qSize; > public int [] where; > > public class qItem{ > public int item; > public int key; > > public qItem(int item, int key){ > //consructor > this.item = item; > this.key = key; > } > } > > public PriorityQueue(int maxItem){ > //constructor of an empty queue: see below > qItem [] Q = new qItem[maxItem]; You define Q again here in the constructor which means Q is a local variable to the constructor and you are NOT referencing the instance variable Q defined in the class. > > int [] where = new int[maxItem]; > for( int j=0; j < maxItem; j++){ > where[j] = -1; > Q[j] = new qItem(-2, -3); > System.out.println(where[j] + " " + Q[j].item + > " " + Q[j].key); > } > int qSize = 0; > }//end constructor > > void insert(int item, int key){ > //insert the item with given key as its priority > qSize++; > System.out.println("qSize: " + qSize); > System.out.println("Item: " + item); > System.out.println("Key: " + key); > for(int i = 0; i < qSize; i++){ > System.out.println(Q[i].item); > System.out.println(Q[i].key); > } > } Any reference to Q here will result in a NullPointerException because again, you are referencing the instance variable Q defined in the class but never initialized. Remove the qItem[] from the Q in the public constructor so that you are referencing the instance variable Q. Doing so and running with a queue size of 1 and an item/key value of 1/1, I see the following: -1 -2 -3 qSize: 1 Item: 1 Key: 1 -2 -3 Is this more of what you are looking for? -- Perry Hoekstra E-Commerce Architect Talent Software Services perry.hoekstra@talentemail.com From phil at rephil.org Sun Mar 3 14:56:07 2002 From: phil at rephil.org (Phil Mendelsohn) Date: Mon Jan 17 14:29:34 2005 Subject: [TCLUG-DEVEL] Java detail In-Reply-To: References: <20020303184132.GA10054@rephil.org> Message-ID: <20020303205607.GB10054@rephil.org> On Sun, Mar 03, 2002 at 01:24:43PM -0600, Chris McKinley wrote: > 1) Nothing is ever inserted into the queue. Thanks -- found it (See 4 below). > 2) Queues usually have push()/pop() methods which insert/remove elements. > The element at the front is usually accessed with a front() method. Yes, this was just a snippet. > type. You will need to use Integers instead of ints. If the assignment > disallows use of Java's collections, then disregard this. Yes, specified to do it from first principles. Thanks for the tips, though. > 4) I don't understand the use of 2 arrays. what is the where[] array for? There is a method implemented later that removes a specific item from the queue, but in order to run in O(lg n) time, it's necessary to keep an index array. > 5) Your primary problem here is this: scoping. Take a look at your > constructor for scoping issues. Is a definition hiding another > definition? Yes -- I found that. Cleared everything right up. Thanks again! -- www.rephil.org "Trying to do something with your life is like sitting down to eat a moose." --Douglas Wood From phil at rephil.org Sun Mar 3 14:58:45 2002 From: phil at rephil.org (Phil Mendelsohn) Date: Mon Jan 17 14:29:34 2005 Subject: [TCLUG-DEVEL] Java detail In-Reply-To: <3C828710.99D8D12C@mn.uswest.net> References: <20020303184132.GA10054@rephil.org> <3C828710.99D8D12C@mn.uswest.net> Message-ID: <20020303205845.GC10054@rephil.org> On Sun, Mar 03, 2002 at 02:26:57PM -0600, Perry Hoekstra wrote: > By the way, you are missing a '}' at the end. Sorry -- this was just a snippet from the front of the class. It was failing early in the program in which is was to be used. > A couple of questions, > first is: aItem a inner class? Second, do you have a main method that you > use for testing? The reason I ask is I am not quite sure what the class > is supposed to do and a main/test method would help me walk through the > processing. I'd be happy to show you -- this class is imported by a test program -- but at this point it's academic, unless you're just curious. -- www.rephil.org "Trying to do something with your life is like sitting down to eat a moose." --Douglas Wood From asmntbuilder at earthlink.net Tue Mar 5 07:17:51 2002 From: asmntbuilder at earthlink.net (Tom Howard) Date: Mon Jan 17 14:29:34 2005 Subject: [TCLUG-DEVEL] Request for assistance for a beginner Message-ID: <3C84C57D.A65F4E7E@earthlink.net> I'm just getting started w/Linux and am having no luck trying to configure my computer to hook up to the internet. I'm running Red Hat & other versions, and jockeying two modems around trying to find a connection. I can bring my computer to someone in the Twin Cities area, if there is someone from whom I could purchase some basic technical assistance. Thanks, Tom From crumley at belka.space.umn.edu Tue Mar 5 08:42:59 2002 From: crumley at belka.space.umn.edu (Jim Crumley) Date: Mon Jan 17 14:29:34 2005 Subject: [TCLUG-DEVEL] Request for assistance for a beginner In-Reply-To: <3C84C57D.A65F4E7E@earthlink.net> References: <3C84C57D.A65F4E7E@earthlink.net> Message-ID: <20020305084258.A21256@gordo.space.umn.edu> On Tue, Mar 05, 2002 at 07:17:51AM -0600, Tom Howard wrote: > I'm just getting started w/Linux and am having no luck trying to > configure my computer to hook up to the internet. I'm running Red Hat & > other versions, and jockeying two modems around trying to find a > connection. I can bring my computer to someone in the Twin Cities > area, if there is someone from whom I could purchase some basic > technical assistance. Thanks, Tom First off, you'll get better response to this type of question from the regular TCLUG list, than from the TCLUG development list, which deals more with programming questions and has fewer people subscribed. For this reason, I'm sending this message to both lists. If you're not already subscribed to the TCLUG list, you might want to join. Second off, I'm sure some one will be able to give you a hand, but it would be helpful if you provided some more information. A few pieces of information you might want to supply: the version of Red Hat (and whatever other distributions you've tried), the model of computer you're trying to install on, the brands and models of the modems you've tried, the tool within Red Hat you're trying to use to set up the modem connection, and the ISP you're trying to connect to. There's probably more info that would be useful, but you get the idea. -- Jim Crumley |Twin Cities Linux Users Group Mailing List (TCLUG) crumley@fields.space.umn.edu |Minneapolis/St. Paul, Minnesota Ruthless Debian Zealot |http://www.mn-linux.org/ Never laugh at live dragons |Dmitry's free,Jon's next? http://faircopyright.org From tanner at real-time.com Fri Mar 8 00:24:22 2002 From: tanner at real-time.com (Bob Tanner) Date: Mon Jan 17 14:29:34 2005 Subject: [TCLUG-DEVEL] cvs tags, patches = problems Message-ID: <20020308002422.M22223@real-time.com> I have a patch in cvs, part of the patch looks like this: -# $Id: genbasedir,v 1.20 2001/11/30 20:40:27 kojima Exp $ +# $Id: genbasedir,v 1.21 2001/12/12 14:50:43 kojima Exp $ The problem is when I commit the patch to cvs the $Id$ tag gets expanded thus rendering the patch invalid. Anyway to make cvs not expand the $Id$ tag? -- Minneapolis St. Paul Twin Cities MN | Phone : (952)943-8700 http://www.mn-linux.org Minnesota Linux | Fax : (952)943-8500 Key fingerprint = 6C E9 51 4F D5 3E 4C 66 62 A9 10 E5 35 85 39 D9 From dave at droyer.org Fri Mar 8 01:06:01 2002 From: dave at droyer.org (Dave Royer) Date: Mon Jan 17 14:29:34 2005 Subject: [TCLUG-DEVEL] cvs tags, patches = problems In-Reply-To: <20020308002422.M22223@real-time.com> References: <20020308002422.M22223@real-time.com> Message-ID: <1015571161.1109.107.camel@merlin> Is this a new file being aded to cvs? If so, simply add it with the -ko option to turn off all keyword substitution for the file. You can't turn off a just specific keyword. If you mean you want to turn it off for just one commit, I don't think you can do that...or if you can, I have no idea how! Here's a link to the relavent page in the cvs manual. http://www.cvshome.org/docs/manual/cvs_12.html#SEC101 Dave On Fri, 2002-03-08 at 00:24, Bob Tanner wrote: > I have a patch in cvs, part of the patch looks like this: > > -# $Id: genbasedir,v 1.20 2001/11/30 20:40:27 kojima Exp $ > +# $Id: genbasedir,v 1.21 2001/12/12 14:50:43 kojima Exp $ > > The problem is when I commit the patch to cvs the $Id$ tag gets expanded thus > rendering the patch invalid. > > Anyway to make cvs not expand the $Id$ tag? > From lamfada at lugh.net Fri Mar 8 10:09:32 2002 From: lamfada at lugh.net (Chris McKinley) Date: Mon Jan 17 14:29:34 2005 Subject: [TCLUG-DEVEL] cvs tags, patches = problems In-Reply-To: <20020308002422.M22223@real-time.com> Message-ID: To turn off keyword expansion for an update, etc, use the -kk option, so cvs update -kk. However, my guess is that you want *.diff or whatever to always have keyword expansion supressed. In that case, you need to checkout the CVSROOT/cvswrappers as the repository administrator and add a line like this: *.diff -kk Now, on to my next question, why are you keeping patches in cvs? Since cvs can generate diffs which you can use to make patches, keeping patches themselves seems redundant. Normally, you would checkout the source, apply the patch, and checkin the modified code. The only exception that I have seen to this is the [FNO]BSD ports where there are BSD specific patches to the source which need to be maintained in the ports cvs because they are from the BSD teams, not from the original author. -Chris McKinley finger lamfada@lugh.net for GPG key On Fri, 8 Mar 2002, Bob Tanner wrote: > I have a patch in cvs, part of the patch looks like this: > > -# $Id: genbasedir,v 1.20 2001/11/30 20:40:27 kojima Exp $ > +# $Id: genbasedir,v 1.21 2001/12/12 14:50:43 kojima Exp $ > > The problem is when I commit the patch to cvs the $Id$ tag gets expanded thus > rendering the patch invalid. > > Anyway to make cvs not expand the $Id$ tag? > > -- > Minneapolis St. Paul Twin Cities MN | Phone : (952)943-8700 > http://www.mn-linux.org Minnesota Linux | Fax : (952)943-8500 > Key fingerprint = 6C E9 51 4F D5 3E 4C 66 62 A9 10 E5 35 85 39 D9 > > _______________________________________________ > tclug-devel mailing list > tclug-devel@mn-linux.org > https://mailman.mn-linux.org/mailman/listinfo/tclug-devel >