PDA

View Full Version : گفتگو: خطایابی



امیر وی بی
یک شنبه 29 تیر 1393, 10:54 صبح
سلام دوستان من این کد رو نوشتم اما تو کنسول این ارور رو میده.....لطفا هر چی به ذهنتون میرسه بگید تا مشکلم حل شه...

ارور داخل کنسول :

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:159)
at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:178)
at adakpro.a.main(a.java:28)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more




کد :

public static void main(String[] args) throws ClientProtocolException, IOException {
ArrayList<HashMap<String, String>>mylist = new ArrayList<HashMap<String, String>>();


//Get the data (see above)
HttpHost targetHost = new HttpHost("localhost", 8080, "http");
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentiWbi (.newAuthScope(targetHost.getHostName(), targetHost.getPort()),newUsernamePasswordCredentia ls("test@liferay.com", "test"));
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
BasicHttpContext ctx = new BasicHttpContext();
//ctx.setAttribute(ClientContext.AUTH_CACHE,authCach e);
HttpPost post = new HttpPost("/tunnel-web/secure/json");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("serviceClassName","com.liferay.portal.service.CountryServiceUtil"));
params.add(new BasicNameValuePair("serviceMethodName", "getCountries"));
params.add(new BasicNameValuePair("serviceParameters", "[]"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
post.setEntity(entity);
HttpResponse resp = httpclient.execute(targetHost, post, ctx);
resp.getEntity().writeTo(System.out);
httpclient.getConnectionManager().shutdown();

}

}

Ehsan rashydy
یک شنبه 29 تیر 1393, 13:52 عصر
باید jar فایل commons-logging.jar رو به classpath اضافه کنی.

خطای java.lang.NoClassDefFoundError
وقتی اتفاق میفته که شما زمان کامپایل یه کلاسی رو داشته باشی، اما موقع اجرا .class اون کلاس رو نداشته باشی، به عبارتی classloader نتونه اون کلاسی که داری استفاده میکنی رو پیدا کنه و در نتیجه لودش کنه.