stretchr
stretchr

Reputation: 615

Java Compiler Issue: cannot find symbol

I am trying to format a String into a date but getting java compiler error:

The fragment of code is:

String value = String.valueOf(entry.getValue());
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
//String dateInString = value;
SimpleDateFormat parse = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.ENGLISH);
if (isFirst){
   Date date = parse.parse(value);
   //Then I'll just put the date variable into a cell in the html table. 

The error I am getting:

cannot find symbol

 [javac] symbol  : constructor SimpleDateFormat(java.lang.String,java.util.Locale)
     [javac] location: class com.lb.base.util.extra.SimpleDateFormat
     [javac]                             SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
     [javac]                                                          ^

I get this for both times I am declaring new SimpleDateFormat. I have checked that import is not the issue. Quite confused to what it is then..why am I getting this 'cannot find symbol' error?

Upvotes: 1

Views: 23693

Answers (4)

stretchr
stretchr

Reputation: 615

Thanks folks, I fixed it by commenting out the first import com.lb.base.util.extra.SimpleDateFormat

and adding

import java.text.SimpleDateFormat;

below it. Guess we can't let the two imports happen at the same time.

Upvotes: 3

saladinxu
saladinxu

Reputation: 402

Apparently you're trying to import com.lb.base.util.extra.SimpleDateFormat

Did you mean to import the java.text one? If yes try changing to below:

import java.text.SimpleDateFormat;

Or change the line you call the constructor:

java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);

Upvotes: 1

aliteralmind
aliteralmind

Reputation: 20163

Something in your code, or the code your using, is very oddly expecting a non-standard version of a very standard class. You should search the source-code for this import statement:

import  com.lb.base.util.extra.SimpleDateFormat;

or for a class/java file named SimpleDateFormat.java

This is pretty difficult to diagnose without having direct access to your computer, but it seems like you are trying to use two classes with exactly the same name.

One other thought: Instead of this

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);

try explicit package names to bypass import statements:

xbn.text.SimpleDateFormat formatter = new xbn.text.SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);

I am assuming here that you want to use the standard Java versions.

Here is a link with some information that may be instructive:

https://www.google.com/search?q=is+already+defined+in+a+single-type+import+%5Bjavac%5D+import

Upvotes: 0

user695992
user695992

Reputation:

Your import seems to be off. You want to use java's SimpleDataFormat and not com.lb.base.util.extra whatever that is.

Upvotes: 1

Related Questions