Results 1 to 6 of 6
  1. #1
    artemff is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Question What in my function incorrect?

    Please, can you see my function. Compiler don't want compile
    strings like (temp[j] == char(0x0D)).
    Error: '.class' expected

    Function must return string with number = index(counting from 0) from
    text.

    Java Code:
     public String ReadStr(int index, String str)
       {
         int len = str.length();
         char []temp = str.toCharArray();
         int p = 0;
         int num = 0;
         for (int i = 0; i < len; i++)
          {
            if (index == p)
             {
               num = i;
               break;
             }
            if (temp[j] == char(0x0D)) p++;
            if ((temp[j] == char(0x0A)) && (j > 0) && (temp[j-1] != char(0x0D))) p++;
          }
         if (temp[num] == char(0x0A)) num++;
         StringBuffer s = new StringBuffer();
         for (int j = num; j < len; j++)
          {
            if ((temp[j] == char(0x0D))||(temp[j] == char(0x0A))) break;
            s.append(temp[j]);
          }
         return s.toString().trim();
       }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Here:
    Java Code:
    if ((temp[j] == char(0x0A)) && (j > 0) && (temp[j-1] != char(0x0D))) p++;
    what is the variable "j"?

    Also, to cast to char,you need to have the char word in parenthesis like so:
    Java Code:
    if (x == (char)(0x0A)) {
    But most importantly, you doing too much coding between compiles. I recommend that you compile after every line or two has been added and that you don't add any more lines until your current code compiles, else you risk creating code that is nothing more than a rat's nest of errors.

  3. #3
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    char(0x0D)? what does this do?

    scanning through apis

    Character

    Character (Java 2 Platform SE v1.4.2)


    String

    String (Java 2 Platform SE v1.4.2)

  4. #4
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    Casting done with

    Java Code:
     public String ReadStr(int index, String str)
       {
         int len = str.length();
         char []temp = str.toCharArray();
         int p = 0;
         int num = 0;
         for (int i = 0; i < len; i++)
          {
            if (index == p)
             {
               num = i;
               break;
             }
    
    [SIZE="6"]J here ..maybe you meant i..and for casting you have to put (char)[/SIZE]
         
    
      [B] if (temp[j] == (  char  )(0x0D)) p++;
      [/B]   
    
    
       if ((temp[j] == char(0x0A)) && (j > 0) && (temp[j-1] != char(0x0D))) p++;
          }
         if (temp[num] == char(0x0A)) num++;
         StringBuffer s = new StringBuffer();
         for (int j = num; j < len; j++)
          {
            if ((temp[j] == char(0x0D))||(temp[j] == char(0x0A))) break;
            s.append(temp[j]);
          }
         return s.toString().trim();
       }

  5. #5
    artemff is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Exclamation

    Fubarable,
    Sorry, I incorrectly copied. In first loop variable i insteed j, but error in other...
    if (x == (char)(0x0A)) {
    O, thanks. Now all work. I will try not to ask such stupid questions more.

  6. #6
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

Similar Threads

  1. Replies: 3
    Last Post: 12-04-2009, 04:08 PM
  2. Class problem: getting incorrect output
    By mgm2010 in forum New To Java
    Replies: 9
    Last Post: 04-30-2009, 08:17 AM
  3. Incorrect Package? Help!
    By chaits86 in forum NetBeans
    Replies: 10
    Last Post: 12-17-2008, 04:08 AM
  4. The addition program is providing incorrect sum '0'
    By tabrez_k81 in forum New To Java
    Replies: 4
    Last Post: 12-16-2008, 02:43 PM
  5. Dubugger points to incorrect source code
    By gdias in forum Eclipse
    Replies: 0
    Last Post: 09-02-2008, 09:07 PM

Posting Permissions

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