cannot find symbol method d(java.lang.String,java.lang.String)
When I compile the code below error occurs:
canot find symbol location: interface org.apache.commons.logging.Log Log.d(TAG,"JSON parsing error - fix it:" + e.getMessage());`
This is my code:
//convertJSONtoArray
private void convertJSONtoArray(String rawJSON){
try {
JSONObject completeJSONObj = new JSONObject(rawJSON);
String json =开发者_如何学运维 completeJSONObj.toString();
Log.d(TAG,json);
JSONObject results = completeJSONObj.getJSONObject("results");
} catch (JSONException e) {
Log.d(TAG,"JSON parsing error - fix it:" + e.getMessage());
}
}
There are two possible reasons:
1. You are using Android
In that case replace the import for Apache Commons Logging Log with:
import android.util.Log;
2. You are developing in normal Java environment
Your import statement at the top of your class includes Apache Commons Logging Log, but the code was definitely not written for Commons Logging.
For Commons Loggig is should look like this:
private static final Log LOG = LogFactory.getLog(NAME_OF_YOUR_CLASS.class);
private void convertJSONtoArray(String rawJSON){
try {
JSONObject completeJSONObj = new JSONObject(rawJSON);
String json = completeJSONObj.toString();
if (LOG.isDebugEnabled()) {
LOG.debug(TAG,json);
}
JSONObject results = completeJSONObj.getJSONObject("results");
} catch (JSONException e) {
if (LOG.isDebugEnabled()) {
LOG.debug(TAG,"JSON parsing error - fix it:" + e.getMessage());
}
}
}
精彩评论