Home | Community | Message Board


Crestline Sales - MycoPath
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, 1 month 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, 1 month
Re: help with C# arrays... [Re: moog]
    #4436977 - 07/22/05 05:25 AM (12 years, 1 month 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, 1 month
Re: help with C# arrays... [Re: TheCow]
    #4436987 - 07/22/05 05:32 AM (12 years, 1 month 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: 7 months, 14 days
Re: help with C# arrays... [Re: TheCow]
    #4437049 - 07/22/05 07:26 AM (12 years, 1 month 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, 1 month 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
* Why the hell won't Media Player play load playlist in correct order??
( 1 2 all )
Viveka 4,902 21 04/20/15 12:51 AM
by Viveka
* iPod help!! MistaUNGA 355 0 06/03/07 10:52 PM
by MistaUNGA
* help with my comp. MeatSpace 762 11 04/05/05 11:33 PM
by OJ
* please help with spyware/virus protection programs Edge 1,664 19 04/06/05 11:26 AM
by trendal
* Homemade tivo KrazieH8er 880 3 11/23/03 01:06 PM
by fungusamongus
* Information travelling faster than 'light' ..
( 1 2 3 all )
cleeen 5,936 58 09/12/07 09:49 PM
by cleeen
* So what exactly is a photon?
( 1 2 3 4 5 6 all )
GumbyM 8,041 115 09/12/07 09:38 PM
by cleeen
* how long is the coast of britain?
( 1 2 all )
Krishna 2,115 21 03/16/09 02:38 PM
by DieCommie

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

Copyright 1997-2017 Mind Media. Some rights reserved.

Generated in 0.033 seconds spending 0.008 seconds on 19 queries.