Incompatible type  -  use of String datatype?

I tried to compile the program but it seems to show "synax errors".
What I complied the program below:
import java.util.Scanner;
public class String
   public static void main(String[] args)
      // declare constants and variables
      String tutorName;
      String stdtName;
      // read input data
      Scanner scn = new Scanner(System.in);
      System.out.print("Enter tutor's name : ");
      tutorName = scn.next();
      System.out.print("Enter student's name : ");
      stdtName = scn.next();
      // display output
      System.out.println ("Tutor's Name : " + tutorName);
      System.out.println ("Tutor's Name : " + stdtName);
}The error message says:
----jGRASP exec: javac -g D:\String.java
String.java:20: incompatible types
found : java.lang.String
required: String
tutorName = scn.next();
                                ^
String.java:22: incompatible types
found: java.lang.String
required: String
stdtName = scn.next();
                              ^
2 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.Edited by: soulhealer88 on May 28, 2008 8:11 AM

BIJ001 wrote:
java.lang.String tutorName;
That would quickly become painful. It's much easier to rename your own class to be different from String.
Big tip: and don't forget to delete your String.class, because if you don't it will continue to trip you up.

Similar Messages

  • JOptionPane showInputDialog incompatible types

    I want an Input dialog from JOptionpane
    I have the following code:
    String anss=JOptionPane.showInputDialog(win,mes,tit,JOptionPane.QUESTION_MESSAGE,new ImageIcon(""),opts,"0");
    [\code]
    win is a JFrame
    mes and tit are Strings
    opts is a String array
    I get an incompatible types, object found, string required error, jbuilder is underling win red.
    I simply have no idea what is happening here.
    Does anybody have an idea?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    solved it myself the return value is Object.

  • Incompatible types - found java.lang.String but expected int

    This is an extremely small simple program but i keep getting an "incompatible types - found java.lang.String but expected int" error and dont understand why. Im still pretty new to Java so it might just be something stupid im over looking...
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Lab
    public static void main(String []args)
    int input = JOptionPane.showInputDialog("Input Decimal ");
    String bin = Integer.toBinaryString(input);
    String hex = Integer.toHexString(input);
    System.out.println("Decimal= " + input + '\n' + "Binary= " + bin + '\n' + "Hexadecimal " + hex);
    }

    You should always post the full, exact error message.
    Your error message probably says that the error occurred on something like line #10, the JOptionPane line. The error is telling you that the compiler found a String value, but an int value was expected.
    If you go to the API docs for JOptionPane, it will tell you what value type is returned for showInputDialog(). The value type is String. But you are trying to assign that value to an int. You can't do that.
    You will need to assign the showInputDialog() value to a String variable. Then use Integer.parseInt(the_string) to convert to an int value.

  • Incompatible types required boolean found string

    I am trying to set a value for a variable called Location when ever the value for the location is "AFRICA"
    I need to reset it to be "55555".
    What I am getting is that 'Incompatible types required boolean found string' under the if statemant. Can anyone shade some light on this?
    String Location = filename.substring(12,17);
    String AP = "AFRICA";
    System.out.println(Location);
    if (Location = AP)
    System.out.println(Location);
    Location = "55555";
    thanks

    rp0428 wrote:
    The IF condition needs to be a BOOLEAN. The '=' is used to do an assignment. The boolean would be '=='.
    But to compare strings why aren't you using
    if (Location.equalsIgnoreCase(AP) {
    To stress this a little more:
    <tt>==</tt> applied between References will compare the Adresses they point to. This means this will only be true if both References point to the identical Object. @Test
    testStringEquality(){
       String s1 = "my Test"
       String s2 = "Test"
      Assert.assertTrue("This strings are equal",s1.equals("my "+s2));
      Assert.assertFalse("This strings are not identical",s1 == ("my "+s2));
    }So use <tt>==</tt> only for primitive number types (those starting with a lower case letter).
    bye
    TPD

  • How to use type cast change string to number(dbl)?can it work?

    how to use type cast change string to number(dbl)?can it work?

    Do you want to Type Cast (function in the Advanced >> Data Manipulation palette) or Convert (functions in the String >> String/Number Conversion palette)?
    2 simple examples:
    "1" cast as I8 = 49 or 31 hex.
    "1" converted to decimal = 1.
    "20" cast as I16 = 12848 or 3230 hex.
    "20" converted to decimal = 20.
    Note that type casting a string to an integer results in a byte by byte conversion to the ASCII values.
    32 hex is an ASCII "2" and 30 hex is an ASCII "0" so "20" cast as I16 becomes 3230 hex.
    When type casting a string to a double, the string must conform the the IEEE 32 bit floating point representation, which is typically not easy to enter from the keyboard.
    See tha attached LabView 6.1 example.
    Attachments:
    TypeCastAndConvert.vi ‏34 KB

  • Incompatible Type When Using Interface

    I have an interface: public interface Generator { ... }
    I have a class that implements the above interface:
    public class MySQLGenerator implements Generator { ... }
    In my main program, I have:
    Generator g = new MySQLGenerator();
    The error message I got is "incompatible types
    found: MySQLGenerator
    required: Generator"

    Check your classpath, and that you are actually importing the Generator you think you are. Also check that there's no other class named Generator in your classpath - the only reason I can think of for what's happening is that there's another Generator class somewhere that's being used. This would explain the invalid reference compilation error.
    Mcf

  • Incompatible types in case statement

    I'm getting incompatible types inside this case statement :
    inString = s_in.readUTF();
                switch (inString.substring(1,3))
                    case nam:
                        ChatClient.nameArea.append(inString);
                        break;
                    case txt:
                        ChatClient.chatArea.append( "\n >>>" + inString );
                        break;
                }If you want, or need to see more or all of the code in this class, just ask.

    This is because you can't use Strings within a switch statement. Use if statements instead.

  • [SOLVED] XSD simpleType trying to assign incompatible types

    Hi all!
    I have a big XSD schema with complex and simple types defined. One of the simple types looks like this (string with min and max length defined):
         <xsd:simpleType name="MySimpleType">
              <xsd:restriction base="xsd:string">
                   <xsd:minLength value="1" />
                   <xsd:maxLength value="36" />
              </xsd:restriction>
         </xsd:simpleType>I assign (copy operation) a string variable to an element of this type. When I compile i get the trying to assign incompatible types warning. I know it's just a warning but I'd like to solve it. I thought I can create a variable of the same type, but I can't (if I try to define message type only the complex type from XSD are displayed).
    Is there a way to get rid of this warning?
    Thanks

    instead of using a variable assignment use the expression builder to construct the 'bpws:getVariableData() equivalent of the variable assignment. The warning will no longer exist.

  • ORABPEL-10041 Trying to assign incompatible types

    Hi,
    I'm developing a BPEL process which takes an input xml file and inserts data into AP interface tables. I used a file adapter to read the input file and used applications adapter to import ap interface tables.
    I use the assign activity to assign the number value from my xml file to the invoice_id column in the ap_invoices_interface column. I get the following warning. Can anyone please tell me how do I fix this. I have BPEL 10.1.2.2 installed.
    Warning(29):
    [Error ORABPEL-10041]: Trying to assign incompatible types
    [Description]: in line 29 of "C:\OraBPELPM_1\integration\jdev\jdev\mywork\Workspace1\BPELProcess_TestInsert\BPELProcess_TestInsert.bpel", <from> value type "{http://www.w3.org/2001/XMLSchema}string" is not compatible with <to> value type "{http://www.w3.org/2001/XMLSchema}long".
    [Potential fix]: Please make sure that the return value of from-spec query is compatible with the to-spec query.
    Thanks

    This is just a warning so it does not mean that your process will fail, e.g. string to decimal may work for the string holds a number, but will fail if it has a string.
    So if you know the data you can safely ignore, otherwise you will have to do some transofrmation within an assign.
    cheers
    James

  • Incompatible  types

    I get the following error message:
    headoffice.java:181: incompatible types
    found : java.lang.String
    required: int
    switch (sa[3]) //sa[3] contains customer type
    ^
    headoffice.java:183: incompatible types
    found : java.lang.String
    required: int
    case �B�:
    ^
    headoffice.java:186: incompatible types
    found : java.lang.String
    required: int
    case �G�:
    ^
    3 errors
    ...and it is associated with the piece of code below. I do not understand in what way the �G� and �B� are incompatible types with sa[3] which is supposed to hold strings.
    StringTokenizer st=new StringTokenizer(s, �*�);     
    String[] sa=new String[st.countTokens()]; int i=0;          
    while(st.hasMoreTokens())
    sa=st.nextToken();     
    i++;               
    switch (sa[3]) //sa[3] contains customer type
    case �B�:
    BronzeCustomer anotherBronzeCustomer = new BronzeCustomer(sa[0], sa[1]);     break;
    case �G�:
    GoldCustomer anotherGoldCustomer = new GoldCustomer(sa[0], sa[1]);     break;
    default: return;
    // break;     
    What is the problem here?
    Regards
    TJ

    If you are using only 1-character strings, then you can do:
       switch (sa[3].charAt(0)) //sa[3] contains customer type
          case 'B': // ...
          case 'G': // ...
          // etc.
       }

  • Incompatible Type?

    Trouble at the end of this code involving incompatible types within word = listEasy.get(wordArrayLocation); along with the other two in that method. Says it needs a java.lang.String.
    import java.util.Random;
    import java.util.Scanner;
    import java.util.ArrayList;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.FileNotFoundException;
    import java.lang.String;
    public class WordArray
       public WordArray() throws FileNotFoundException
          Creation of 3 word arrays based off of the desired level of game difficulty
          ArrayList<String> listEasy = new ArrayList<String>();
          ArrayList<String> listIntermediate = new ArrayList<String>();
          ArrayList<String> listHard = new ArrayList<String>();
          //open the physical files (words*.txt) for use in the corresponding ArrayList
          FileReader readerEasy = new FileReader("wordsEasy.txt");
          FileReader readerIntermediate = new FileReader("wordsIntermediate.txt");
          FileReader readerHard = new FileReader("wordsHard.txt");
          use a Scanner object called "in*" to access the respective file handle.  
          Scanner inEasy = new Scanner(readerEasy);
          Scanner inIntermediate = new Scanner(readerIntermediate);
          Scanner inHard = new Scanner(readerHard);
       Use a loop to walk through the input file WordsEasy.txt reading one line at a time. 
       while (inEasy.hasNext())
          String record = inEasy.next();
          listEasy.add(record);
       Use a loop to walk through the input file WordsIntermediate.txt reading one line at a time. 
       while (inIntermediate.hasNext())
          String record = inIntermediate.next();
          listIntermediate.add(record);
       Use a loop to walk through the input file WordsHard.txt reading one line at a time. 
       while (inHard.hasNext())
          String record = inHard.next();
          listHard.add(record);
       inEasy.close();
       inIntermediate.close();
       inHard.close();
       set ListEasy's size
       public int setListEasySize()
          listEasySize = listEasy.size();
       set ListIntermediate's size
       public int setListIntermediateSize()
          listIntermediateSize = listIntermediate.size();
       set ListHard's size
       public int setListHardSize()
          listHardSize = listHard.size();
       public int setGeneratorLength(int difficultyLevel)
          if (difficultyLevel == 3)
             generatorLength = listHardSize - 1;
          else if(difficultyLevel == 2)
             generatorLength = listIntermediateSize - 1;
          else
             generatorLength = listEasySize - 1;
          Picks a random word
          @return
       public int randWord()
          Random generator = new Random();
          wordArrayLocation = generator.nextInt(generatorLength);
       public String getWord(int difficultyLevel)
          if (difficultyLevel == 3)
             word = listHard.get(wordArrayLocation);
          else if(difficultyLevel == 2)
             word = listIntermediate.get(wordArrayLocation);
          else
             word = listEasy.get(wordArrayLocation);
          return word;
       private String word;
       private int wordArrayLocation;
       private int generatorLength;
       private int listEasySize;
       private int listIntermediateSize;
       private int listHardSize;
       private ArrayList<WordArray> listEasy;  
       private ArrayList<WordArray> listIntermediate;
       private ArrayList<WordArray> listHard;
    }

    Here is what I have changed things to...
    import java.util.Random;
    import java.util.Scanner;
    import java.util.ArrayList;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.FileNotFoundException;
    import java.lang.String;
    public class WordArray
       public WordArray() throws FileNotFoundException
          Creation of 3 word arrays based off of the desired level of game difficulty
          //open the physical files (words*.txt) for use in the corresponding ArrayList
          FileReader readerEasy = new FileReader("wordsEasy.txt");
          FileReader readerIntermediate = new FileReader("wordsIntermediate.txt");
          FileReader readerHard = new FileReader("wordsHard.txt");
          use a Scanner object called "in*" to access the respective file handle.  
          Scanner inEasy = new Scanner(readerEasy);
          Scanner inIntermediate = new Scanner(readerIntermediate);
          Scanner inHard = new Scanner(readerHard);
       Use loops to walk through the input file reading one line at a time. 
          while (inEasy.hasNext())
             String record = inEasy.next();
             listEasy.add(record);
          while (inIntermediate.hasNext())
             String record = inIntermediate.next();
             listIntermediate.add(record);
          while (inHard.hasNext())
             String record = inHard.next();
             listHard.add(record);
       inEasy.close();
       inIntermediate.close();
       inHard.close();
       set the size of of the arraylists to a variable.
       public void setListEasySize()
          listEasySize = listEasy.size();
       public void setListIntermediateSize()
          listIntermediateSize = listIntermediate.size();
       public void setListHardSize()
          listHardSize = listHard.size();
       //Set the difficulty level from user input  
       public void setDifficultyLevel(int difficulty)
          difficultyLevel = difficulty;
       //Calculate the wanted randomm generator length depending on the difficulty level
       public void setGeneratorLength()
          if (difficultyLevel == 3)
             generatorLength = listHardSize - 1;
          else if(difficultyLevel == 2)
             generatorLength = listIntermediateSize - 1;
          else
             generatorLength = listEasySize - 1;
       // Calculates what random arraylist location to pull an object from
       public void randWord()
          Random generator = new Random();
          wordArrayLocation = generator.nextInt(generatorLength);
          Sets the selected arraylist object to another object
       public void setWordObject()
          if (difficultyLevel == 3)
             wordObject = (listHard.get(wordArrayLocation));
          else if(difficultyLevel == 2)
             wordObject = listIntermediate.get(wordArrayLocation);
          else
             wordObject = listEasy.get(wordArrayLocation);
          returns the word
          @return
       public String getWord()
          word = wordObject.toString();
          return word;
       private ArrayList<String> listEasy = new ArrayList<String>();
       private ArrayList<String> listIntermediate = new ArrayList<String>();
       private ArrayList<String> listHard = new ArrayList<String>();
       private String word;
       private Object wordObject;
       private int difficultyLevel;
       private int wordArrayLocation;
       private int generatorLength;
       private int listEasySize;
       private int listIntermediateSize;
       private int listHardSize;
    }Edited by: jojavawuz on Nov 19, 2008 8:34 AM

  • Incompatible type error

    I am receiving the following errors:
    incompatible types
    found: int
    required: boolean
    if (accessCode = 8345)
    if (accessCode = 55875)
    if (accessCode = 999909)
    I do not understand why I am getting the errors. accessCode is of type int.
    Thanks in advance for any input.
    int accessCode = Integer.parseInt( String.valueOf(
      securityCodeJPasswordField.getPassword() ) );
         int code;
         if (accessCode >= 1645 && accessCode <= 1689)
             code = 1;
         else
         if (accessCode  = 8345)
                code = 2;
         else
         if (accessCode = 55875)
             code = 3;
         else
         if (accessCode = 999898)
             code = 4;
         else
         if (accessCode >= 1000006 && accessCode <= 1000008)
             code = 5;
         else
         if (accessCode < 1000)
             code = 6;
         else
                        code = accessCode;

    Thanks !! I am stuck in the coding syntax that I use in my job: SAS

  • Incompatible Types... NOT!

    Why am I getting incompatible types in this method?
    C:\jdk1.3\src\CalcBusinessDays.java:53: incompatible types
    found : java.util.Date
    required: Date
              Date covDate = sdf.parse(dt, pos);^ <-- carat is at end of line
         public Date dateConvert(String dt) {
              SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
              ParsePosition pos = new ParsePosition(0);
              Date covDate = sdf.parse(dt, pos);
              return covDate;
         }     //dateConvert
    Thanks in advance.

    Actually I'm in Hartford, CT, where NJ sends its rain! I used to live in Staten Island which is close to NJ as you know. Also worked in Parsippany for a while.
    I think "Date" needs to be changed to "java.util.Date" in three places. See comments below where changes are marked. I could not compile or test because I don't have Domino / Notes.
    By the way, in case you get similar problems with another class (Calendar?), I believe that the lotus.domino classes are AgentBase, AgentContext, Session and DateTime. The others should be standard Java classes. Good Luck.
    import java.util.*;
    import java.text.*;
    import java.math.*;
    import lotus.domino.*;
    public class CalcBusinessDays extends AgentBase {
        public void NotesMain() {
            DateTime startTime = null, endTime = null;
            String startTimeStr, endTimeStr, result;
            try {
                Session session = getSession();
                AgentContext agentContext = session.getAgentContext();
                startTimeStr = "04/12/2000";
                endTimeStr = "05/04/2000";
                startTime = session.createDateTime(startTimeStr);
                endTime = session.createDateTime(endTimeStr);
                result = diffInWeekdays(startTime, endTime, startTimeStr,
                endTimeStr);
                System.out.println("Result = " + result);
            } catch(Exception e) {
                e.printStackTrace();
        } //NotesMain
        public String diffInWeekdays(DateTime startTime, DateTime endTime, String startTimeStr, String endTimeStr) {
            String res = "";
            try {
                Date firstDate = null, secondDate = null;
                int diffInt = endTime.timeDifference(startTime);
                int diffIntDays = (diffInt / 86400 + 1);
                BigInteger sev = BigInteger.valueOf(7);
                BigInteger minusTwo = BigInteger.valueOf(-2);
                BigInteger bis = BigInteger.valueOf(getWeekday(firstDate = dateConvert(startTimeStr)));
                BigInteger bie = BigInteger.valueOf(getWeekday(secondDate = dateConvert(endTimeStr)));
                int strtDay = bis.mod(sev).intValue();
                int endDay = bie.mod(sev).intValue();
                int max = minusTwo.max(BigInteger.valueOf(strtDay * -1)).intValue();
                int min = BigInteger.valueOf(1).min(bie.mod(sev)).intValue();
                int result = (diffIntDays - endDay + strtDay - 8) * 5 / 7 - max - min + 5 - strtDay + endDay;
                //o.println("result =\t" + result);
                res = Integer.toString(result);
            } catch (Exception e) {
                e.printStackTrace();
            return res;
        } //diffInWeekdays
        public java.util.Date dateConvert(String dt) {          // *** changed
            SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
            ParsePosition pos = new ParsePosition(0);
            java.util.Date covDate = sdf.parse(dt, pos);       // *** changed
            return covDate;
        } //dateConvert
        public int getWeekday(java.util.Date cdt) {            // *** changed
            Calendar cal = Calendar.getInstance();
            cal.setTime(cdt);
            return cal.get(Calendar.DAY_OF_WEEK);
        } //getWeekday
    } //CalcBusinessDays

  • Incompatible types in simple odbc statements

    this is my simple code
    import java.sql.*;
    public class QueryApp {
         public static void main(String a[]){
              try{
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection con;
                   con=DriverManager.getConnection("jdbc:odbc:MyDataSource","nik","123456");
                   Statement stat=con.createStatement();
                   stat.executeQuery("Select * from Publishers");
              catch(Exception e){
                   System.out.println("Error:"+e);
    }after this when i compile i get these errors
    QueryApp.java:15: incompatible types
    found   : java.sql.Connection
    required: Connection
                con=DriverManager.getConnection("jdbc:odbc:MyDataSource","nik","123456");
                                                           ^
    QueryApp.java:16: cannot find symbol
    symbol  : method createStatement()
    location: class Connection
                Statement stat=con.createStatement();
                                              ^
    2 errorsCan some body help me on this error as searching on net wasn't fruitfull?

    1) You probably created a Connection class your compiler tries to use instead of java.sql.Connection. I advise to rename your class, or at least use the fully qualified classname for declaring con.
    2) The Connection class you created does not have such a method.

  • Neophyte: Incompatible Types

    Hi all, new to programming and Java in particular. Here is the code:
    import java.net.*;
    import java.io.*;
    class WHWWW {
         public static void main (String[] arg) {
              URL u = new URL("http://www.google.gov/");
              FilterInputStream ins = u.openStream();
              InputStreamReader isr = new InputStreamReader(ins);
              BufferedReader whiteHouse = new BufferedReader(isr);
              System.out.println(google.readLine());
    Here is the error:
    Incompatible Types
    found: java.io.InputStream
    required: java.io.FilterInputStream
    FilterInputStream ins = u.openStream();
    ^
    Thanks for the help.

    Create one of the subclasses of FilterInputStream
    instead of InputStream. Perhaps BufferedInputStream
    would be appropriate here.
    Whoops. That should have been ]Create one of the subclasses of FilterInputStream instead, using InputStream (as the argument to the constructor). Perhaps BufferedInputStream would be appropriate here.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • Adobe flash player and labview

    Hi How can I make labview interact with adobe flash player and read variables? Adobe flash player is displayed by internet explorer and I'm using Adobe Flash player 10, with labview 8.2

  • How do I get my iTunes back after doing a operating system restore?

    I recently had to restore my operating system and redownload iTunes. All of my music files were backed up but I was wondering if there was a way to restore my entire iTunes library instead of tediously add files and folders to library? And will this

  • Problems in Global Outline Agreement

    Hi friends,                       We are using SRM 5.0 and R/3 4.7.I want to replicate contract to SRM 5.0 to R/3. For that I have to configure Global Outline Agreement. After creating and distributing GOA i am facing 2 errors. I got those errors fro

  • Exchange Management Console Tools Compatibility

    Is there a timeline for getting a compatible version of this software for Windows 8 Enterprise x64.  As an IT Professional, this is really getting in the way of my ability to enjoy your new OS.  I have work to do, and its not enjoyable bouncing back

  • Extract query-text from a cursor: is possible?

    Is possibile, having a cursor like that: cursor c is select name, phone from addressbook; ...extract the "query text", i.e. a varchar2 variable (str) so that it contains: str = 'select name, phone from addressbook'