Home | Community | Message Board


Vaposhop
Please support our sponsors.

General Interest >> Science and Technology

Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!

Jump to first unread post. Pages: 1
Invisiblemoog
Stranger

Registered: 02/15/05
Posts: 1,296
help with C# arrays...
    #4434790 - 07/21/05 07:47 PM (12 years, 8 months ago)

I doubt a lot of people here know C#, but I figure I'll ask anyway. This language is pissing me off. I'm used to doing easy stuff like PHP or Python.

Anyway here's the problem. I'm getting a NullRefereneceException when I loop through an array. Here's the relevant code...
Code:

string[] titles = new string[30];
string[] addresses = new string[30];
FileStream playlist = new FileStream("ess.pls",FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(playlist);
string fullList = sr.ReadToEnd();
string[] array = fullList.Split("\r\n".ToCharArray());
sr.Close();
playlist.Close();
int i = 0, tx = 0, ax = 0;
while (i < array.Length) {
// the problem is within this while loop...
if (array[i].IndexOf("Title") > -1) {
titles[tx] = array[i].Remove(0,array[i].IndexOf("ESS"));
tx++;
}
if (array[i].IndexOf("http") > -1) {
addresses[ax] = array[i].Remove(0,array[i].IndexOf("http"));
ax++;
}[/b]
i++;
}



And when I compile I get
Quote:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
in <0x00340> SimpleApp:Main ()





Well it's pretty apparent that it's talking about the arrays but I don't know what to do about it. Is this just telling me to handle the exception and then it will work, or is it an actual problem with my code? Sorry if I sound absolutely clueless because I am. :confused:


Post Extras: Print Post  Remind Me! Notify Moderator
OfflineTheCow
Stranger

Registered: 10/28/02
Posts: 4,790
Last seen: 9 years, 9 months
Re: help with C# arrays... [Re: moog]
    #4436977 - 07/22/05 05:25 AM (12 years, 8 months ago)

Ha nevermind. I will have to look atthis while not on 30mg of oxycontin.


Edited by TheCow (07/22/05 05:27 AM)


Post Extras: Print Post  Remind Me! Notify Moderator
OfflineTheCow
Stranger

Registered: 10/28/02
Posts: 4,790
Last seen: 9 years, 9 months
Re: help with C# arrays... [Re: TheCow]
    #4436987 - 07/22/05 05:32 AM (12 years, 8 months ago)

maybe you have to initialize all your arrays? Ha ok iacant se very wel. Tomoorrow!


Post Extras: Print Post  Remind Me! Notify Moderator
OfflineSeussA
Error: divide byzero

Folding@home Statistics
Registered: 04/27/01
Posts: 23,480
Loc: Caribbean
Last seen: 16 days, 20 hours
Re: help with C# arrays... [Re: TheCow]
    #4437049 - 07/22/05 07:26 AM (12 years, 8 months ago)

Hmm... I don't know C#, but it is basically Java stolen from Sun and slapped with a new name...

Code:
while (i < array.Length) {
if (array[i].IndexOf("Title") > -1) {
//
// What happens if array[i].IndexOf("ESS") doesn't exist? Probably
// need to check for this condition before calling the Remove() method.
//
// Are you sure that tx < titles.Length ?
//
titles[tx] = array[i].Remove(0,array[i].IndexOf("ESS"));
tx++;
}
if (array[i].IndexOf("http") > -1) {
//
// Are you sure that ax < addresses.Length ?
//
addresses[ax] = array[i].Remove(0,array[i].IndexOf("http"));
ax++;
}
i++;
}



--------------------
Just another spore in the wind.


Post Extras: Print Post  Remind Me! Notify Moderator
Invisiblemoog
Stranger

Registered: 02/15/05
Posts: 1,296
Re: help with C# arrays... [Re: Seuss]
    #4437596 - 07/22/05 12:33 PM (12 years, 8 months ago)

wow...

Well it appears that the problem was totally unrelated to the code I posted. :rolleyes: It was actually farther down in my gui implementation. Apparently I was trying to append values to a Gtk ListStore that was undefined. ugh... thanks anyway.  :smile:


Post Extras: Print Post  Remind Me! Notify Moderator
Jump to top. Pages: 1

General Interest >> Science and Technology

Similar ThreadsPosterViewsRepliesLast post
* Format String Attack (you gotta be experienced with coding)
( 1 2 all )
Xeny 2,178 22 03/06/08 06:46 PM
by Diploid
* String Theory and Quantum Physics.
( 1 2 all )
ergot 3,900 24 01/03/04 03:02 AM
by MarioNett
* String Theory Silversoul 838 8 10/02/05 04:41 PM
by DieCommie
* Is string theory scientific? Silversoul 845 13 01/06/09 04:44 PM
by cortex
* ATTN: PHP/MySQL Gurus
( 1 2 all )
elbisivni 1,584 20 09/04/07 08:04 PM
by elbisivni
* Monkeys 'string words together' DiploidM 662 14 05/29/06 11:23 AM
by relativexistance
* in regards to the 'how long is a piece of string' thang I AM SWIM 657 12 02/28/11 11:01 PM
by DieCommie
* String Theory dblaney 1,590 10 05/18/05 06:45 PM
by dblaney

Extra information
You cannot start new topics / You cannot reply to topics
HTML is disabled / BBCode is enabled
Moderator: Lana, trendal, automan
568 topic views. 0 members, 3 guests and 0 web crawlers are browsing this forum.
[ Toggle Favorite | Print Topic | Stats ]
Search this thread:
Vaposhop
Please support our sponsors.

Copyright 1997-2018 Mind Media. Some rights reserved.

Generated in 0.024 seconds spending 0.007 seconds on 19 queries.