Results 1 to 6 of 6
  1. #1
    CodeMonkeyAlx is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Error telling me something is not initialized

    Hello Hello, Its been a while since I have been here but I figured I might as well post this little issue I am having.
    First: Here is my situation, I am re-learning Java from the ground up while writing tutorials to my blog Found here Basically these tutorials are my cliff notes from the book I am reading (Core Java (Version 9) -- Great Book if you are serious about programming!) So I have run into a slight snag in some of my own code that I could use a hand with so here it is:

    Java Code:
    		String sentence = "This is a basic sentence sequence using letters and spaces in unicode!";
    		int index = sentence.offsetByCodePoints(0, i);
    		int cp = sentence.codePointAt(i);
    		System.out.println(index);
    		if (Character.isSupplementaryCodePoint(cp)) i += 2;
    		else i++;
    		System.out.println(i);
    It is telling me that "i" is not initialized (Sorry forgot to mention this!)

    Any quick advice on this would be great. I know its likely a newbie mistake but I would rather ask for help and get a fresh set of eyes looking at it than wrack my brain if the answer is right in front of me.

    Thanks for your time!

  2. #2
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Re: Error telling me something is not initialized

    Where did you initialize i?

  3. #3
    CodeMonkeyAlx is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Error telling me something is not initialized

    Ahh I think I see what you mean...... Let me try something and get back to you.

  4. #4
    CodeMonkeyAlx is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Error telling me something is not initialized

    I fixed it by adding the following:

    Java Code:
    int i = 0;
    Thanks for the hint @Wnt2bsleepin

  5. #5
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Re: Error telling me something is not initialized

    Indeed. Do you know why it wasn't working before though? Why is that needed?

  6. #6
    CodeMonkeyAlx is offline Member
    Join Date
    Aug 2012
    Posts
    13
    Rep Power
    0

    Default Re: Error telling me something is not initialized

    Simply put you can use a variable which technically does not exist in the code before trying to use it!

Similar Threads

  1. variable may not have been initialized...
    By ajetrumpet in forum New To Java
    Replies: 6
    Last Post: 03-24-2013, 11:35 AM
  2. Replies: 4
    Last Post: 06-29-2012, 10:05 PM
  3. Replies: 14
    Last Post: 09-07-2011, 01:16 AM
  4. Replies: 3
    Last Post: 06-14-2011, 09:35 PM
  5. compiler telling me to make a file for a public class
    By silverglade in forum New To Java
    Replies: 10
    Last Post: 04-26-2011, 07:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •