Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Unexpected type

  1. #1
    Member
    Join Date
    Mar 2014
    Posts
    70
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Unexpected type

    Hi.
    This is a snapshot of my code:
       public class sysinfoHooshi implements ActionListener{
        		class Info{			
    			public String name;
    			public String version;
    			public String arch;
    			public double ramUtil;
    			public double CPUUtil;
    		};
     
        JTextField  tf = new JTextField("");
        JTextField  tf2 = new JTextField("");
        JDialog dialog = new  JDialog();	
     
        /****************Query dialog variables*******************/
        JDialog quesryDialog = new  JDialog();	
        JCheckBox chkCPUUtil = new JCheckBox("CPU utilization");
        JCheckBox chkRAMUtil = new JCheckBox("RAM utilization");
        JCheckBox chkVersion = new JCheckBox("Version of the OS");
        JCheckBox chkArch = new JCheckBox("Processor architecture");
        JCheckBox chkName = new JCheckBox("Operating system name");
        boolean nameChecked, versionChecked, archChecked, CPUChecked, RAMChecked;
        /*********************************************************/
     
    	public  void simulate()throws Exception{
     
    	this.showDialog();
    		int simTime = Integer.parseInt( tf.getText() );;
    		int interval = Integer.parseInt( tf2.getText() );
     
     
    		int queueSize = 60*simTime/interval;
     
    		System.out.println( queueSize );
     
     
     
    		Info[] queue = new Info[queueSize];
     
    		int pos = 0;
     
    		for(int i=0;i<queueSize;++i)
    		  queue[i]  = new Info();
     
     
    		for(int i=0;i<queueSize;++i)
    		{
    			TimeUnit.SECONDS.sleep(interval);
    			OperatingSystemMXBean osBean = (com.sun.management.OperatingSystemMXBean)
    			ManagementFactory.getOperatingSystemMXBean();
    			queue[pos].name = System.getProperty("os.name");
    			queue[pos].version = System.getProperty("os.version");
    			queue[pos].arch = System.getProperty("os.arch");
    		//	queue[pos].ramUtil =100-( osBean.getFreePhysicalMemorySize()/osBean.getTotalPhysicalMemorySize() ) * 100;		
    		//		queue[pos].CPUUtil = ( osBean.getSystemCpuLoad() ) * 100;
    		++pos;
    		}//end for  
     
    		showQueryDialog();
     
    		chkName.addItemListener = (new ItemListener() {
    			public void itemStateChanged( ItemEvent e)
    			{ e.getStateChenge()==1 ? nameChecked=true :nameChecked = false;}
    		});
     
    		chkVersion.addItemListener = (new ItemListener() {
    			public void itemStateChanged( ItemEvent e)
    			{ e.getStateChenge()==1 ? versionChecked=true :versionChecked = false;}
    		});
     
    		chkArch.addItemListener = (new ItemListener() {
    			public void itemStateChanged( ItemEvent e)
    			{ e.getStateChenge()==1 ? archChecked=true :archChecked = false;}
    		});
     
    		chkCPUUtil.addItemListener = (new ItemListener() {
    			public void itemStateChanged( ItemEvent e)
    			{ e.getStateChenge()==1 ? CPUChecked=true :CPUChecked = false;}
    		});
     
    		chkRAMUtil.addItemListener = (new ItemListener() {
    			public void itemStateChanged( ItemEvent e)
    			{ e.getStateChenge()==1 ? RAMChecked=true :RAMChecked = false;}
    		});
     
    	}//end simulate()
     
    	public void showDialog()
    	{
    	...
    	 public void actionPerformed(ActionEvent e) {
    		 ...
    	}
     
    	public void showQueryDialog()
    	{
    		...
    	}
    /*	
    	public void showResults(Info queue)
    	{
    		String results = "";
     
    		if(nameChecked)
    		  results += queue[i].name;
     
    		if(archChecked)
    	}
    */
     
     
    public static void main(String args[]) throws Exception{	
    ...
    	} // end main
       }// end class

    What are the unexpected type errors?

    EDIT: The compiller specifically hints at e.getStateChanged() == 1, but it is used in the example on http://www.tutorialspoint.com/swing/swing_jcheckbox.htm without any problems(I compiled that successfelly)
    Last edited by hooshdar3; July 17th, 2014 at 08:12 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Unexpected type

    You tell us. What lines are the errors on? What types are you working with on those lines? What types is it expecting?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Mar 2014
    Posts
    70
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: Unexpected type

    Quote Originally Posted by KevinWorkman View Post
    You tell us. What lines are the errors on? What types are you working with on those lines? What types is it expecting?
    I have told you:lines with getStateChange() == 1.
    Unfortunately I cannot name number.This forum doesn't show line numbers.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Unexpected type

    The posted code:
    e.getStateChenge()==1
    is different from the error message:
    hints at e.getStateChanged() == 1
    Can you copy the fulll and EXACT text of the error message and post it. What was posted does not make sense. The code and the error message do not agree.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Unexpected type

    Quote Originally Posted by hooshdar3 View Post
    The compiller specifically hints at e.getStateChanged() == 1
    The compiler doesn't "hint" at anything. It gives you very specific errors.

    You have multiple syntax errors in this code. You're using the ternary operator incorrectly, and you have a random if statement without a body. I honestly recommend starting over from scratch and *compiling often*. You shouldn't wait until you have a whole program written to compile it. You should compile it every time you add something new.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Member
    Join Date
    Mar 2014
    Posts
    70
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: Unexpected type

    Quote Originally Posted by KevinWorkman View Post
    The compiler doesn't "hint" at anything. It gives you very specific errors.

    You have multiple syntax errors in this code. You're using the ternary operator incorrectly, and you have a random if statement without a body. I honestly recommend starting over from scratch and *compiling often*. You shouldn't wait until you have a whole program written to compile it. You should compile it every time you add something new.
    Hey, those "if"'s are commented out

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Unexpected type

    Quote Originally Posted by hooshdar3 View Post
    Hey, those "if"'s are commented out
    Okay, fair enough. You're still using the ternary operators incorrectly. The ternary operator must evaluate to a value, not an expression. So you can't do this:

    x > 0 ? y = 1 : y = 2;

    You can't do that because y=1 and y=2 are expressions, not values. Instead, you'd have to do something like this:

    y = x > 0 ? 1 : 2;

    Now the ternary operator evaluates to a value (1 or 2), which is then assigned to y.

    If you want to use expressions, then you need to use an if statement, not a ternary operator.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. The Following User Says Thank You to KevinWorkman For This Useful Post:

    hooshdar3 (July 17th, 2014)

  9. #8
    Member
    Join Date
    Mar 2014
    Posts
    70
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default Re: Unexpected type

    Quote Originally Posted by Norm View Post
    The posted code:

    is different from the error message:


    Can you copy the fulll and EXACT text of the error message and post it. What was posted does not make sense. The code and the error message do not agree.
    sysinfoHooshi.java:72: unexpected type
    required: variable
    found : value
    { e.getStateChange()==1 ? nameChecked=true :nameChecked = false;}
    ------------------------------------------------------------------------
    same errors at other such lines. Please don't pay attention to line numbers

Similar Threads

  1. unexpected output
    By sumitroy in forum Threads
    Replies: 4
    Last Post: June 30th, 2014, 07:30 AM
  2. unexpected results to simple program
    By Pajaro in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 30th, 2013, 12:51 PM
  3. Unexpected Output Format
    By playinmyblues in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 13th, 2012, 06:56 PM
  4. Unexpected ArrayOutOfBoundsError
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 28th, 2010, 04:00 AM
  5. ArrayList Unexpected Return
    By Cammack in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2010, 09:23 PM