0

The code is too big to paste the entire when i am having one error at Line 20 that says:
"cannot make static reference to non-static Integer"
I'm use to C but so I'm not use to having to putting the word static in places.

private static void createTree(){
		ArrayList arrayOfInts = new ArrayList();
		
	
		T t = new T();
		TreeNode root = t.getRoot();
		
		System.out.println("Please enter a list of integers:");
	
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		String result = null;

		
		try {
		
			while((result = in.readLine()) !=null)
			{
				Integer intResult = Integer.parseInt(result); //error: cannot make static reference to non-static Integer
			//	Integer intResult = result;  //error: cannot make static reference to non-static Integer
			    System.out.println("intResult:"+intResult);
			//	insertInOrder(root, intResult);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		//this means your done inputing. 
		//this means your done inputing. 
	}
	
	/**
	 * Instantiates a new t.
	 */
	public T()
	{
		super();
		root = new TreeNode();
	}
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by sunny101
0

You can't reference a non static class variable from a static method. The class varible only exists in created objects (ie with new).
Why does the code want to see a variable belonging to an object when there is no object?
If the variable is static then there is only one of it available to everyone.

0

No, that can't be it because I already tried using the primitive type int and that had the same error:
int intResult = result; //error: cannot make static reference to non-static Integer

But also tried it like you said and put new Integer but I still get the same error:
Integer intResult = new Integer.parseInt(result); //error: cannot make static reference to non-static Integer

0

Please write a SHORT program to demo the problem and post it here with the error messages.

The type of the variable is not relevant. Integer vs int would make no difference.

0

you are trying to make reference to a variable of type string from premitive variable which is not possible. declare your variable "result" as int.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.