JAVA Problem

Discussion in 'Software' started by e_f_w_a, Sep 18, 2004.

  1. e_f_w_a

    e_f_w_a Private E-2

    hello... I'm new on java programming and i have this code...
    public String gettok(String getTokenText,int MinWord,int MaxWord,int seperatorAscii) {
    char outputChars[] = null;
    int destination_counter = 0;
    int loop = 0;
    show_text("HERE IS FINE...");
    while (loop < getTokenText.length()) {
    show_text("UNTIL HERE IT IS FINE");
    outputChars[destination_counter++] = getTokenText.charAt(loop++);
    show_text("THIS IS NOT WORKING");
    }
    show_text("THIS IS NOT WORKING");
    return outputChars.toString() + "NOT...";
    }
    please tell me what's wrong :\
     
  2. rmStar-R

    rmStar-R Private E-2

    the problem is this statement:

    outputChars[destination_counter++] = getTokenText.charAt(loop++);

    that says you are adding something from nothing as stated by your line:

    outputChars[] = null;

    you may be able to solve the problem by creating the outputChars to have an initial length equal to getTokenText.length(). I don't know how you are going to implement your test for the gettok() function but other means of circumventing the "empty" initial size or segmentation error.

    why don't you use

    outputChar[ loop++ ] = getTokenText.charAt( loop++ );

    instead and save memory by freing the space for destination_counter?

    Is it not possible to use String for your outputChars instead?

    outputChars.charAt( loop++ ) = getTokenText.charAt( loop++ );
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds