• Register
1 vote
18 views

Problem:

Hi,

I started adopting the Java programming language a few days back. For the time being, I’ve written a java program that should print values from my StudentDatabase using an object of it. Inside my StudentDatabase, I have all the values I need to access. But the problem occurs when I am trying to execute the program. The compiler throws an error. It says string cannot be resolved to a type. I am attaching my codes snippet and error message below. Please, fix the error and save my time Thanks

import java.util.Scanner;

class StudentDatabase{
    string name;
    int age;
    long telephone;
}

public class MyProgram{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in) ;
        StudentDatabase myobject = new StudentDatabase();
        System.out.print("Enter Your Good Name: ");
        myobject.name= sc.nextLine();
        sc.nextLine();
        System.out.print("Enter Your Age: ");
        myobject.age = sc.nextInt();
        System.out.println("Enter Your 6 - Digit telephone Number: ");
        myobject.telephone = sc.nextLong();
   }

}

And the error I am getting

MyProgram.java:4: error: cannot find symbol
    string name;
    ^
  symbol:   class string
  location: class StudentDatabase
1 error

 

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes

Solution:

You need to remind that, Java is a highly case sensitive language. In Java, the uppercase and lowercase letters are treated in different ways. You are getting that error because of violating the naming convention of java data-type. There is no such data-type as ‘string’. You wanted to write it as “String”. You can read the convention here

So, to fix the error, just change the data-type name from “string” to “String” and your program should run fine. 

Good Day!

13 9 6
94,240 points

Related questions

0 votes
1 answer 4 views
4 views
Problem: How to fix this error: chromedriver cannot be resolved to a type Can someone please help fix this, I am new in java chromedriver cannot be resolved to a type Any anyone ideas on what I need to do to fix this? Thanks!
asked 3 days ago Ali 5.9k points
0 votes
1 answer 18 views
18 views
Problem: I am developing a dynamic web project (RESTful jersey) under Eclipse IDE. Under src/my/demo/service folder I have CarService.java class public class CarService { ... }
asked Feb 1 Ali 5.9k points
0 votes
1 answer 17 views
17 views
Problem: The method public boolean mergesWith(Tile moving) returns true if this and moving tiles have the same value. But when I check if they are the same by doing the following: if(this.value == temp.value){ return true; } then it shows me error on temp.value saying that value cannot be resolved or is not a field. How can I fix that?
asked Feb 22 Ali 5.9k points
0 votes
1 answer 2 views
2 views
Problem: Why I got the error : the import java util cannot be resolved HELP! I need help understanding this error: the import java util cannot be resolved Can someone please help fix this, I am new in java. Anyone have ideas on what I need to do to fix this? Thanks!
asked 3 days ago Ali 5.9k points
0 votes
1 answer 13 views
13 views
Problem: I just downloaded and introduced the new android SDK. I needed to make a basic application to test it.The wizard made this code: package eu.mauriziopz.gps; import android.app.Activity; import android.os.bundle; public class ggps extends Activity { /** Called when the ... .main); } } but eclipse showed me the given error: R cannot be solved setContentView(R.layout.main); Why is it so?
asked Feb 15 sasha 13.2k points
0 votes
1 answer 9 views
9 views
Any help or guidance would be much appreciated! Thank you
asked Dec 16, 2020 TeamScript 13.5k points
0 votes
1 answer 19 views
19 views
Problem: Trying to use the following code: List<Integer> list = new List<Integer>(); I get the following error message: java.util.List is abstract; cannot be instantiated What does this mean and why can't I initialize a List the same way I would an ArrayList?
asked Feb 22 Ali 5.9k points
0 votes
2 answers 8 views
8 views
Problem: Running a maven web project in eclipse was giving errors on jsp pages:javax.servlet.jsp.pagecontext cannot be resolved to a typejavax.servlet.jsp.jspexception Running a Maven web project in eclipse was giving errors on jsp pages: javax.servlet.jsp.PageContext cannot be resolved to a type javax.servlet.jsp.JspException cannot be resolved to a type
asked Feb 24 Ali 5.9k points
0 votes
1 answer 10 views
10 views
what else do I need to check? please help.
asked Feb 17 TeamScript 13.5k points
0 votes
1 answer 8 views
8 views
I did this and it fixed the issue for some time - but it is reappearing. I am not sure if I have any more jar collisions.
asked Feb 11 TeamScript 13.5k points