The Artima Developer Community
Sponsored Link

Java Answers Forum
Novice to Java needs help.

6 replies on 1 page. Most recent reply: Nov 24, 2009 10:14 AM by Abe Johnson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Abe Johnson

Posts: 5
Nickname: tubutas
Registered: Nov, 2009

Novice to Java needs help. Posted: Nov 19, 2009 10:32 AM
Reply to this message Reply
Advertisement
import java.util.HashMap;
 
public HashMap makeList(String List1[], String List2[]){
	HashMap List=new HashMap();
	for(int x=0;x<List1.length;x++)List.put(List1[x],List2[x]);
	return List;
}
 
public static void main(){
	HashMap man=makeList(new String[]{"Name","Age"},new String[]{"Tubutas","17"}); //This line has the error



The compiler I run this through [BlueJ] gives me a compile-time error saying.

Cannot find symbol - method makeList(java.lang.String[],java.lang.String[])


When i took away the new String[] part BlueJ says

Illegal Start of Expression


Abe Johnson

Posts: 5
Nickname: tubutas
Registered: Nov, 2009

Re: Novice to Java needs help. Posted: Nov 19, 2009 10:39 AM
Reply to this message Reply
Well, thats strange...

var String LIST[]={"Tubutas","17"};
makeList(LIST,LIST);


Gives the same error

Cannot find symbol - method makeList(java.lang.String[],java.lang.String[])

George B

Posts: 24
Nickname: hmgeorge
Registered: Feb, 2008

Re: Novice to Java needs help. Posted: Nov 19, 2009 11:13 AM
Reply to this message Reply
Try changing your makeList method to static.

    public static HashMap makeList(String List1[], String List2[]){

Abe Johnson

Posts: 5
Nickname: tubutas
Registered: Nov, 2009

Re: Novice to Java needs help. Posted: Nov 23, 2009 10:30 AM
Reply to this message Reply

public static HashMap makeList(String List1[], String List2[]){
HashMap List=new HashMap();
for(int x=0;x<List1.length;x++)List.put(List1[x],List2[x]);
return List;
}


Same error.


String XD[]={"LOL!"};
HashMap LOL=makeList(XD,XD);


Still doesn't work

George B

Posts: 24
Nickname: hmgeorge
Registered: Feb, 2008

Re: Novice to Java needs help. Posted: Nov 23, 2009 1:23 PM
Reply to this message Reply
Hmm. It compiles okay for me that way. I made a few tweaks to get the whole thing to compile and run as a class and it compiled and ran fine. Here's the output:

man [{Name=Tubutas, Age=17}]

and here's the source:

import java.util.HashMap;
 
public class Test {
    public static HashMap makeList(String[] List1, String[] List2){
	HashMap List=new HashMap();
	for(int x=0;x<List1.length;x++)List.put(List1[x],List2[x]);
	return List;
    }
 
    public static void main(String[] args){
	HashMap man=makeList(new String[]{"Name","Age"},new String[]{"Tubutas","17"}); //This line has the error
        System.out.println("man [" + man + "]");
    }
}

Abe Johnson

Posts: 5
Nickname: tubutas
Registered: Nov, 2009

Re: Novice to Java needs help. Posted: Nov 24, 2009 10:12 AM
Reply to this message Reply
When i copy that code verbatim it compiles and runs fine, but when i try importing the function from my main class it fails

import java.util.HashMap;
import Tubutas.TStringLib; //This class contains all my important functions
 
public class Test {
    public static void main(String[] args){
	HashMap man=makeList(new String[]{"Name","Age"},new String[]{"Tubutas","17"}); //This line has the error
        System.out.println("man [" + man + "]");
    }
}


Cannot find symbol - method makeList(java.lang.String[],java.lang.String[])


Also if it helps when spaced out...

import java.util.HashMap;
import Tubutas.TStringLib;
 
public class Test {
    public static void main(String[] args){
	HashMap man
	=
	makeList( //This line has the error
	new String[]{"Name","Age"},
	new String[]{"Tubutas","17"}
	);
        System.out.println("man [" + man + "]");
    }
}


Cannot find symbol - method makeList(java.lang.String[],java.lang.String[])

Abe Johnson

Posts: 5
Nickname: tubutas
Registered: Nov, 2009

Re: Novice to Java needs help. Posted: Nov 24, 2009 10:14 AM
Reply to this message Reply
WOW! I feel silly....

This whole time i thought it wasn't accepting the strings, but in reality, i forgot to call my TStringLib.makeList()

Flat View: This topic has 6 replies on 1 page
Topic: a java error I don't understand ? Previous Topic   Next Topic Topic: illegal start of expression...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use