簡體   English   中英

Java編譯器問題:找不到符號

[英]Java Compiler Issue: cannot find symbol

我正在嘗試將字符串格式化為日期,但出現Java編譯器錯誤:

代碼片段是:

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. 

我得到的錯誤:

找不到標志

 [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]                                                          ^

我兩次都聲明新的SimpleDateFormat時得到了這個。 我已經檢查了導入不是問題。 那到底是什么,我很困惑。為什么我會收到“找不到符號”錯誤?

謝謝大家,我通過注釋掉第一個導入com.lb.base.util.extra.SimpleDateFormat來修復它

並添加

import java.text.SimpleDateFormat;

在它下面。 猜猜我們不能讓兩個導入同時發生。

您的導入似乎已關閉。 您要使用Java的SimpleDataFormat,而不要使用com.lb.base.util.extra。

顯然您正在嘗試導入com.lb.base.util.extra.SimpleDateFormat

您是說要導入java.text嗎? 如果是,請嘗試更改為以下內容:

import java.text.SimpleDateFormat;

或更改您調用構造函數的行:

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

奇怪的是,您的代碼中或您使用的代碼中都包含非常標准的類的非標准版本。 您應該在源代碼中搜索此導入語句:

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

或用於名為 SimpleDateFormat.java的類/ java文件

如果不能直接訪問計算機,這很難診斷,但是似乎您正在嘗試使用名稱完全相同的兩個類。

另一個想法:代替這個

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

嘗試使用顯式包名稱繞過導入語句:

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

我在這里假設您使用標准的Java版本。

這是一些信息的鏈接,這些信息可能具有指導意義:

https://www.google.com/search?q=is+已經+定義+ in + a +單一類型+導入+%5Bjavac%5D +導入

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM