0

printStackTrace() is a method in the Exception class. You need to add the object: e. in front of it:
e.printStackTrace();

Where is the print out of the value of the input variable on line 14?

0

ok done that but still showing

List.java:20: cannot resolve symbol
symbol : method printLn (java.lang.String)
location : class java.io.PrintStream
System.out.printLn("Invalid");

0

That's strange. Your code uses that method many times doesn't it? why is it misspelled this one time?
Copy a good one and paste it to replace this one.

Edited by NormR1

0

I did as you suggested and copied and pasted that line of code that had previously worked and everything now compiles file, however its still not allowing me to enter text, if i try for example to enter "paris" into the list it comes up with the following message

java.lang.NumberFormatException: For input string: "paris"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Interger.parseInt(Integer.java:468)
at java.lang.Interger.parseInt(Integer.java:518)
at List.readValue(List.java:15)
at List.insert(List.java:39)
at Listtest.main(Listtest.java:20)

0

The message spells out that your code reads the input into a String then tries to parse that as an Integer.
"paris" is not an integer.
You now have two values to read, one is an integer the other is a string, you can't use exactly the same code for both.

0

honestly I have been trying I've tried to change the line

value = Integer.parseInt(input);

to

value = Integer.toString(input);

but that doesnt seem to work and also tried many other alternatives but nothing I try to do seems to work

0

that doesnt seem to work

Please explain what happens. Post the full contents of the error messages.
Post the ccnsole showing the program's output.

0

It shows error message

List.java:15: cannot resolve symbol
symbol : method toString (java.lang.String)
location : class java.lang.Integer
value = Integer.toString(input);

1 error

0

You need to read the API doc for the Integer class to get the correct syntax and parameters for its toString() method.

0

well i've updated all the code now and getting more errors than ever before I've been at this all day, the new code looks as follows
list.java

 import java.io.*;
    public class List {
        public static Listnode head;
        public List() {
            head = new Listnode("");
        }
        public static int readValue( )throws IOException {
           BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
           String input="";
           String value ="";
           boolean OK = false;
           while (!OK){
              try{
            input = in.readLine();
            value = input;
            OK = true;
            }
            catch (Exception e){
                  System.out.println("Invalid - please enter integer value");
    }

            }
          return value;
        }

        public static boolean isEmpty() {
            if (head.next == null)
                return true;
            else
                return false;
        }


        public static void insert() throws IOException {
           Listnode current, previous, temp;
           String value;
           System.out.print("Enter number to insert, 0 if no more: ");
           value = readValue();
           while (value != 0) {
              temp = new Listnode(value);
              current = head;
              previous = head;
              while ((current.next != null) && (value > current.value)) {
                  previous = current;
                  current = current.next;
                }
               if (value < current.value) {
                   temp.next = current;
                   previous.next = temp;
                } else
                    current.next = temp;
               System.out.print("Enter number to insert, 0 if no more: ");
               value = readValue();                 }

          }

        public static void search() throws IOException {
            Listnode current = head.next;
            String sought;
            boolean found = false;
            if (isEmpty())
                System.out.println("List is empty ");
             else {
                System.out.print(" Value sought: ");
                sought = readValue();
                while ((!found) && !(current == null)) {
                   if (current.value == sought) {
                       System.out.println(sought + " is in the list ");
                       found = true;
                     }
                    current = current.next;
                  }
                 if (!found)
                   System.out.println("Item is not in the list ");
            }
        }

        public static void deleteItem() throws IOException {
               Listnode current, previous, temp;
               String sought;
               boolean found = false;
               if (isEmpty())
                   System.out.println("List is empty ");
               else {
                System.out.print("Item to delete: ");
                sought = readValue();
                current = head;
                previous = head;
                while (!found && !(current == null)) {
                    if (current.value == sought) {
                       previous.next = current.next;
                       System.out.println(sought + " deleted from list ");
                       found = true;
                   }
                  else {               
                      previous = current;
                      current = current.next;
                     }
                }
                if (!(found))
                    System.out.println("Item is not in the list ");
              }

            }

        public static void writeList() {
            Listnode current = head.next;
            if (isEmpty())
                System.out.println("List is empty ");
            else {
                while (current != null) {
                    System.out.println(current.value);
                    current = current.next;
                }
            }
        }
    }

Listtest.java

   import java.io.*;

    public class Listtest {
        public static int readValue( ) {
           BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
           String input ="";
           String value ="";
           boolean OK = false;
           while (!OK){


            }
          return value;
        }

        public static void main(String[] args) throws IOException {
            List mylist = new List();
            int choice = 7;
            System.out.println("Start by adding some items to the list...");
            mylist.insert();
            while (choice != 0) {
                System.out.println(
                        "------------------------------------------");
                System.out.print(
                        "1..Write out list  2..Insert items 3..Search 4..delete 0..Quit: ");
                choice = readValue();
                if (choice == 1)
                    mylist.writeList();
                else if (choice == 2)
                    mylist.insert();
                else if (choice == 3)
                    mylist.search();
                else if (choice == 4)
                    mylist.deleteItem();

            }
        }
    }

Listnode.java

   public class Listnode {
        String value;


        Listnode next;
        public Listnode(String data) {
        value = data;
        next = null;
        }
    }

The error messages are as follows

Listtest.java:13:incompatible types 
found : java.lang.String
required: int
   return value;

List.java:23: incompatible types
found : java.lang.String
required: int
   return value;

List.java:38: incompatible types
found : int
required: java.lang.String
   value = readValue();

List.java:39:operator !=cannot be applied to java.lang.String,int
  while (value !=0 {

List.java:43: operator (cannot be applied to java.lang.String,java.lang.String
while ((current.next !=null) && (value ) current.value)){

List.java:47:operator (cannot be applied to java.lang.String,java.lang.String
  if (value < current.value){

 List.java:53: incompatible types
 found : int
 requires: java.lang.String
  value = readValue();

 List.java:65: incompatible types
  found : int
  requires: java.lang.String
   sought = readValue();

   List.java:86: incompatible types
  found : int
  requires: java.lang.String
   sought = readValue();
0

The "required" and "found" errors mean you are using the wrong type of data in the statements with those errors.
You need to change the datatype of the variables in those statements to be what the "required" type is.
Look at each error message and change the variable to be the "required" type.

Edited by NormR1

0

i thought String was a class name?

String is a class name. But you cannot use string instead of String in java it is case sensistive so String and string are not the same as NormR1 had already explained.
Refer Java API for further clarification.

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.