INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

java errors- int cannot be dereferenced

java errors- int cannot be dereferenced

(OP)
I have been tasked with changing a java file that I had to get from a decompiler. I am not so familiar and get errors compiling as follows:
C:\Program Files\IBM\SQLLIB\java\jdk\bin>javac C:\jarsSrc\dbms\Main.java
C:\jarsSrc\dbms\Main.java:258: int cannot be dereferenced
        for(i = Integer.valueOf(0); i.intValue() < lines.length;)
                                     ^
C:\jarsSrc\dbms\Main.java:260: int cannot be dereferenced
            if(lines[i.intValue()].equals((new StringBuilder()).append("NAME: ")
.append(apiname).toString()))
                      ^
C:\jarsSrc\dbms\Main.java:262: int cannot be dereferenced
                j = Integer.valueOf(i.intValue() + 1);
                                     ^
C:\jarsSrc\dbms\Main.java:262: operator + cannot be applied to <any>,int
                j = Integer.valueOf(i.intValue() + 1);
                                              ^
C:\jarsSrc\dbms\Main.java:265: int cannot be dereferenced
            Integer integer1 = i = Integer.valueOf(i.intValue() + 1);
                                                    ^
C:\jarsSrc\dbms\Main.java:265: operator + cannot be applied to <any>,int
            Integer integer1 = i = Integer.valueOf(i.intValue() + 1);
                                                             ^
C:\jarsSrc\dbms\Main.java:269: int cannot be dereferenced
        System.out.println((new StringBuilder()).append("Found API base url for
").append(apiname).append(": Using ").append(lines[j.intValue()]).toString());

                                                    ^
C:\jarsSrc\dbms\Main.java:270: int cannot be dereferenced
        return lines[j.intValue()];
                      ^
8 errors


HERE is the section of code returning the errors:
public static String get_api_url(String apiname)
    {
       
        int i ;
        int j ;
        String lines[];
        String html = getHTML("http://REMOVED BEFORE POSTING");
        html = html.replace("URL: ", "");
        lines = html.split("\n");
        for(i = Integer.valueOf(0); i < lines.length;)
        {
            if(lines[i.intValue()].equals((new StringBuilder()).append("NAME: ").append(apiname).toString()))
            {
                j = Integer.valueOf(i.intValue() + 1);
            }
            Integer integer = i;
            Integer integer1 = i = Integer.valueOf(i.intValue() + 1);
           // integer;
        }

        System.out.println((new StringBuilder()).append("Found API base url for ").append(apiname).append(": Using ").append(lines[j.intValue()]).toString());
        return lines[j.intValue()];
        Exception e;
        
        System.err.println("Can't find this API, returning the default.");
        return "http://REMOVED BEFORE POSTING=";
    }
}

RE: java errors- int cannot be dereferenced

That code is a nightmare, but the function itself looks pretty simple, maybe you should consider rewrinting it from scratch instead of decompiling.

Cheers,
Dian

RE: java errors- int cannot be dereferenced

Hiya,

Has that code definately not been hand modified after decompilation?  The reason I ask is that there is a mix of primitive integers and object Integers.  As an example:

CODE

int i ;
...
for(i = Integer.valueOf(0); i < lines.length;)

You are defining 'i' as a primitive 'int', then trying to assign an 'java.lang.Integer' to it.  You probably just want the following:


CODE

int i ;
...
for(i = 0; i < lines.length;)

I agree with Dian.  You should consider re-writing this function for clarity, but I expect the rest of the code is the same anyway.

Cheers,
Scott  
 

RE: java errors- int cannot be dereferenced

Don't you just love the first one?

for(i = Integer.valueOf(0); i.intValue() < lines.length;)

It doesn't even increment i within the loop!
Once again, concise and apposite advice from Scott...

Busted.

RE: java errors- int cannot be dereferenced

(OP)
Thanks for the advice everyone.
I did rewrite that section of the code (this was only one section/funtion of the whole piece)

here is what I rewrote and it now compiles. Have to wait to see if it does what it is supposed to along with the other code.

public static String get_api_url(String apiname)
    {

        Integer i = 0;
        Integer j = 0;
        
    try {
        
        String html = getHTML("http://REMOVED");
        html = html.replace("URL: ", "");
        String [] lines = html.split("\n");

        for(i = 0; i < lines.length; i++)


        {
            if(lines[i].equals((new StringBuilder()).append("NAME: ").append(apiname).toString()))
            {
                j = i + 1;
            }

        }

        System.out.println((new StringBuilder()).append("Found API base url for ").append(apiname).append(": Using ").append(lines[j]).toString());
        return lines[j];


    } catch (Exception e){

        System.err.println("Can't find this API, returning the default.");
        return "http://REMOVED?byInternetAddr=";
        }
    }

RE: java errors- int cannot be dereferenced

Good decision. Just some points

CODE

public static String get_api_url(String apiname)
    {
      int i = 0;
      try {
        String html = getHTML("http://REMOVED");
        html = html.replace("URL: ", "");
        String [] lines = html.split("\n");
String strToSearch = new StringBuilder().append("NAME: ").append(apiname).toString();

        for(i = 0; i < lines.length; i++) {
            if(lines[i].equals(strToSearch);            
                break;
        }

        System.out.println((new StringBuilder()).append("Found API base url for ").append(apiname).append(": Using ").append(lines[i+1]).toString());
        return lines[i+1];


    } catch (Exception e){

        System.err.println("Can't find this API, returning the default.");
        return "http://REMOVED?byInternetAddr=";
        }
    }

Cheers,
Dian

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close