If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Java: I Can't pass a string variable into array?

I'm new to Java, very very new, and I have encountered a hair raising problem: I can't seem to pass the value of a string variable into a string array. It's very frustrating when I poll the array and get null as far as the eye can see. The code follows:
_________________________
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.String.*;

Basically I'm trying to write a class which accepts input (in the form of an applet) and breaks the words in the input into an array, one array slot for each word. So far, as I said before, sntncArray[wrdCnt]=sntnc.substring(0,x-1); always equals null, in spite of the fact that sntnc.substring(0,x-1); is a valid string. I'm clearly missing something very obvious, but I can't figure out what. I know that strings are objects and not primitives and so I can't use them as primitives (I think) but how can I pass the value of a given string into an array? I even tried making a string to hold the value of sntnc.substring(0,x-1); ("passer") and tried sntncAray[wrdCnt]=passer; but with the same result:Null. Any assistance is greatly appreciated. Greatly greatly. VERY Greatly greatly.
[Thnx]
//end

Could you please enclose your code with [ code ] tags so that it retain the formatting (I hope that it is formatted) and become easier to read. I want to help, but it's really hard when it takes so much effort just to deciper the thing.

I believe substring excludes the last index you specify. Therefore, the -1 will probably return one less character than you want per word.

I'm a little out of practice with Java so I can't dissect your code (however small it is) ATM, and my suggestions probably won't fix your problem. I'll continue looking at it though . However, if this is purely for personal experimentation (and not something you plan to put on the internet where nobody is guaranteed to have JRE 1.4), the String object has had a split(String regex) method since 1.4.

You're sure this doesn't work for you? I compiled and opened it in appletviewer and it worked for me. (BTW what I meant is that you don't have to create a new String class when putting theSntnc.getText() into a new variable).