java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET from linux terminal with twilio -
in small java program run centos terminal, getting java.lang.nosuchfielderror: def_content_charset
error when type in java -cp .:"../dependencies/*" mainpackage.sendtext xxxxxxxxxx hellothere
@ centos 7 terminal. how can resolve error program can run command line?
the terminal input , output follows:
[user@domain bin]$ java -cp .:"../dependencies/*" mainpackage.sendtext xxxxxxxxxx hellothere exception in thread "main" java.lang.nosuchfielderror: def_content_charset @ org.apache.http.impl.client.defaulthttpclient.setdefaulthttpparams(defaulthttpclient.java:175) @ org.apache.http.impl.client.defaulthttpclient.createhttpparams(defaulthttpclient.java:158) @ org.apache.http.impl.client.abstracthttpclient.getparams(abstracthttpclient.java:448) @ com.twilio.sdk.twiliorestclient.<init>(twiliorestclient.java:151) @ com.twilio.sdk.twiliorestclient.<init>(twiliorestclient.java:110) @ mainpackage.sendtext.main(sendtext.java:20)
where xxxxxxxxxx
, hellothere
arguments program, shown below.
note directory structure of code is:
/home/user/javacode #contains sendtext.java /home/user/javacode/bin/mainpackage/ #contains sendtext.class /home/user/javacode/dependencies #contains jar files
i read this other posting stating problem caused redundant versions of httpcore
in classpath
, moved parent directory , did recursive search files httpcore
in name, got following results, seem show 1 version of httpcore
:
[user@domain bin]$ cd /home/user/javacode/ [user@domain javacode]$ find . -name "*http*" ./dependencies/httpcore-4.1.2.jar ./dependencies/httpclient-4.2.3.jar ./dependencies/httpclient-4.2.3.jar.sha1 ./dependencies/httpclient-4.2.3.pom ./dependencies/httpclient-4.2.3.pom.sha1 ./dependencies/httpclient-4.1.2.jar [user@domain javacode]$
the line of code throwing error is: twiliorestclient client = new twiliorestclient(account_sid, auth_token);
, , complete code of small program is:
package mainpackage; import com.twilio.sdk.twiliorestclient; import com.twilio.sdk.twiliorestexception; import com.twilio.sdk.resource.factory.messagefactory; import com.twilio.sdk.resource.instance.message; import org.apache.http.namevaluepair; import org.apache.http.message.basicnamevaluepair; import java.util.arraylist; import java.util.list; public class sendtext { public static final string account_sid = "arealsid"; public static final string auth_token = "arealtoken"; public static void main(string[] args) throws twiliorestexception { twiliorestclient client = new twiliorestclient(account_sid, auth_token); string = args[0]; string body = args[1]; // build filter messagelist list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("body", body)); params.add(new basicnamevaluepair("to", to)); params.add(new basicnamevaluepair("from", "+11234567654")); messagefactory messagefactory = client.getaccount().getmessagefactory(); message message = messagefactory.create(params); system.out.println(message.getsid()); } }
the full contents of /dependencies
folder are:
[user@domain bin]$ cd /home/user/javacode/dependencies [user@domain dependencies]$ ls -al total 39464 drwxrwxr-x 5 user user 8192 aug 24 19:18 . drwxrwxr-x 4 user user 76 aug 21 22:29 .. drwxrwxr-x 2 user user 6 aug 22 05:05 1.2 drwxr-xr-x 2 user user 6 aug 22 03:00 3.4.5 drwxr-xr-x 2 user user 6 aug 22 03:01 4.2.3 -rw-r--r-- 1 user user 445288 aug 24 19:17 antlr-2.7.7.jar -rw-r--r-- 1 user user 4467 aug 24 19:17 aopalliance-1.0.jar -rw-r--r-- 1 user user 119683 aug 24 19:17 aspectjrt-1.7.4.jar -rw-r--r-- 1 user user 1850391 aug 24 19:17 aspectjweaver-1.7.4.jar -rw-r--r-- 1 user user 255692 aug 24 19:17 bcpg-jdk15on-1.51.jar -rw-r--r-- 1 user user 2842667 aug 24 19:17 bcprov-jdk15on-1.51.jar -rw-r--r-- 1 user user 140580 aug 24 19:17 bootstrap-2.3.0.jar -rw-r--r-- 1 user user 156396 aug 24 19:17 common-2.2.3.jar -rw-r--r-- 1 user user 232019 aug 24 19:17 commons-beanutils-1.8.3.jar -rw-r--r-- 1 user user 58160 aug 24 19:17 commons-codec-1.4.jar -rw-r--r-- 1 user user 146108 aug 24 19:17 commons-digester-1.8.1.jar -rw-r--r-- 1 user user 53082 aug 24 19:17 commons-fileupload-1.2.jar -rw-r--r-- 1 user user 87776 aug 24 19:17 commons-io-1.3.2.jar -rw-r--r-- 1 user user 284220 aug 24 19:17 commons-lang-2.6.jar -rw-r--r-- 1 user user 385091 aug 24 19:17 commons-lang3-3.2.1.jar -rw-r--r-- 1 user user 60686 aug 24 19:17 commons-logging-1.1.1.jar -rw-r--r-- 1 user user 61829 aug 22 05:01 commons-logging-1.2.jar -rw-r--r-- 1 user user 40 aug 22 05:01 commons-logging-1.2.jar.sha1 -rw-rw-r-- 1 user user 19206 aug 22 05:01 commons-logging-1.2.pom -rw-rw-r-- 1 user user 40 aug 22 05:01 commons-logging-1.2.pom.sha1 -rw-r--r-- 1 user user 390116 aug 24 19:17 datatables-core-0.9.2.jar -rw-r--r-- 1 user user 5295 aug 24 19:17 datatables-export-itext-0.9.2.jar -rw-r--r-- 1 user user 42220 aug 24 19:17 datatables-jsp-0.9.2.jar -rw-r--r-- 1 user user 6484 aug 24 19:17 datatables-servlet2-0.9.2.jar -rw-r--r-- 1 user user 313898 aug 24 19:17 dom4j-1.6.1.jar -rw-r--r-- 1 user user 750664 aug 24 19:17 ecore-2.2.3.jar -rw-r--r-- 1 user user 1346296 aug 24 19:17 ehcache-core-2.6.6.jar -rw-r--r-- 1 user user 81271 aug 24 19:17 hibernate-commons-annotations-4.0.1.final.jar -rw-r--r-- 1 user user 4613189 aug 24 19:17 hibernate-core-4.2.1.final.jar -rw-r--r-- 1 user user 138093 aug 24 19:17 hibernate-ehcache-4.2.1.final.jar -rw-r--r-- 1 user user 484520 aug 24 19:17 hibernate-entitymanager-4.2.1.final.jar -rw-r--r-- 1 user user 102661 aug 24 19:17 hibernate-jpa-2.0-api-1.0.1.final.jar -rw-r--r-- 1 user user 477382 aug 24 19:17 hibernate-validator-4.3.1.final.jar -rw-r--r-- 1 user user 352254 aug 24 19:17 httpclient-4.1.2.jar -rw-r--r-- 1 user user 433071 aug 22 02:36 httpclient-4.2.3.jar -rw-r--r-- 1 user user 40 aug 22 02:36 httpclient-4.2.3.jar.sha1 -rw-r--r-- 1 user user 5911 aug 22 02:36 httpclient-4.2.3.pom -rw-r--r-- 1 user user 40 aug 22 02:36 httpclient-4.2.3.pom.sha1 -rw-r--r-- 1 user user 181200 aug 24 19:18 httpcore-4.1.2.jar -rw-r--r-- 1 user user 38139 aug 24 19:18 hyperjaxb3-ejb-runtime-0.6.0.jar -rw-r--r-- 1 user user 1810034 aug 24 19:18 itextpdf-5.3.4.jar -rw-r--r-- 1 user user 228268 aug 24 19:18 jackson-core-asl-1.9.3.jar -rw-r--r-- 1 user user 773019 aug 24 19:18 jackson-mapper-asl-1.9.3.jar -rw-r--r-- 1 user user 648253 aug 24 19:18 javassist-3.15.0-ga.jar -rw-r--r-- 1 user user 582024 aug 24 19:18 javax.mail.jar -rw-r--r-- 1 user user 141164 aug 24 19:18 jaxb2-basics-runtime-0.8.2.jar -rw-r--r-- 1 user user 60768 aug 24 19:18 jboss-logging-3.1.0.ga.jar -rw-r--r-- 1 user user 25215 aug 24 19:18 jboss-transaction-api_1.1_spec-1.0.1.final.jar -rw-r--r-- 1 user user 16458 aug 24 19:18 jcl-over-slf4j-1.7.1.jar -rw-r--r-- 1 user user 153253 aug 24 19:18 jdom-1.0.jar -rw-r--r-- 1 user user 581571 aug 24 19:18 joda-time-2.3.jar -rw-r--r-- 1 user user 29691 aug 24 19:18 joda-time-hibernate-1.3.jar -rw-r--r-- 1 user user 34417 aug 24 19:18 joda-time-jsptags-1.1.1.jar -rw-r--r-- 1 user user 155031 aug 24 19:18 jquery-2.0.3-1.jar -rw-r--r-- 1 user user 618763 aug 24 19:18 jquery-ui-1.10.3.jar -rw-r--r-- 1 user user 23931 aug 24 19:18 json-simple-1.1.1.jar -rw-r--r-- 1 user user 16046 aug 24 19:18 json-simple-1.1.jar -rw-r--r-- 1 user user 414240 aug 24 19:18 jstl-1.2.jar -rw-r--r-- 1 user user 264600 aug 24 19:18 logback-classic-1.0.13.jar -rw-r--r-- 1 user user 418870 aug 24 19:18 logback-core-1.0.13.jar -rw-r--r-- 1 user user 98 aug 22 02:31 m2e-lastupdated.properties -rw-r--r-- 1 user user 872300 aug 24 19:18 mysql-connector-java-5.1.27.jar -rw-rw-r-- 1 user user 199 aug 22 05:01 _remote.repositories -rw-r--r-- 1 user user 219683 aug 24 19:18 rome-1.0.jar -rw-r--r-- 1 user user 26084 aug 24 19:18 slf4j-api-1.7.5.jar -rw-r--r-- 1 user user 335679 aug 24 19:18 spring-aop-3.2.5.release.jar -rw-r--r-- 1 user user 359456 aug 24 19:18 spring-aop-4.1.7.release.jar -rw-r--r-- 1 user user 610657 aug 24 19:18 spring-beans-3.2.5.release.jar -rw-r--r-- 1 user user 712395 aug 24 19:18 spring-beans-4.1.7.release.jar -rw-r--r-- 1 user user 865109 aug 24 19:18 spring-context-3.2.5.release.jar -rw-r--r-- 1 user user 1026661 aug 24 19:18 spring-context-4.1.7.release.jar -rw-r--r-- 1 user user 127744 aug 24 19:18 spring-context-support-3.2.5.release.jar -rw-r--r-- 1 user user 178151 aug 24 19:18 spring-context-support-4.1.7.release.jar -rw-r--r-- 1 user user 870616 aug 24 19:18 spring-core-3.2.5.release.jar -rw-r--r-- 1 user user 1008584 aug 24 19:18 spring-core-4.1.7.release.jar -rw-r--r-- 1 user user 382147 aug 24 19:18 spring-data-commons-1.6.2.release.jar -rw-r--r-- 1 user user 161900 aug 24 19:18 spring-data-jpa-1.4.2.release.jar -rw-r--r-- 1 user user 196929 aug 24 19:18 spring-expression-3.2.5.release.jar -rw-r--r-- 1 user user 259197 aug 24 19:18 spring-expression-4.1.7.release.jar -rw-r--r-- 1 user user 405160 aug 24 19:18 spring-jdbc-3.2.5.release.jar -rw-r--r-- 1 user user 426716 aug 24 19:18 spring-jdbc-4.1.7.release.jar -rw-r--r-- 1 user user 205995 aug 24 19:18 spring-jms-3.2.5.release.jar -rw-r--r-- 1 user user 269447 aug 24 19:18 spring-jms-4.1.7.release.jar -rw-r--r-- 1 user user 285829 aug 24 19:18 spring-messaging-4.1.7.release.jar -rw-r--r-- 1 user user 385012 aug 24 19:18 spring-orm-3.2.5.release.jar -rw-r--r-- 1 user user 376254 aug 24 19:18 spring-orm-4.1.7.release.jar -rw-r--r-- 1 user user 74705 aug 24 19:18 spring-oxm-3.2.5.release.jar -rw-r--r-- 1 user user 82949 aug 24 19:18 spring-oxm-4.1.7.release.jar -rw-r--r-- 1 user user 83411 aug 24 19:18 spring-security-acl-3.2.2.release.jar -rw-r--r-- 1 user user 406230 aug 24 19:18 spring-security-config-3.2.2.release.jar -rw-r--r-- 1 user user 359632 aug 24 19:18 spring-security-core-3.2.2.release.jar -rw-r--r-- 1 user user 24511 aug 24 19:18 spring-security-taglibs-3.2.2.release.jar -rw-r--r-- 1 user user 342221 aug 24 19:18 spring-security-web-3.2.2.release.jar -rw-r--r-- 1 user user 242189 aug 24 19:18 spring-tx-3.2.5.release.jar -rw-r--r-- 1 user user 252964 aug 24 19:18 spring-tx-4.1.7.release.jar -rw-r--r-- 1 user user 627339 aug 24 19:18 spring-web-3.2.5.release.jar -rw-r--r-- 1 user user 722215 aug 24 19:18 spring-web-4.1.7.release.jar -rw-r--r-- 1 user user 637193 aug 24 19:18 spring-webmvc-3.2.5.release.jar -rw-r--r-- 1 user user 782723 aug 24 19:18 spring-webmvc-4.1.7.release.jar -rw-r--r-- 1 user user 26664 aug 24 19:18 tiles-api-2.1.3.jar -rw-r--r-- 1 user user 135193 aug 24 19:18 tiles-core-2.1.3.jar -rw-r--r-- 1 user user 55083 aug 24 19:18 tiles-jsp-2.1.3.jar -rw-r--r-- 1 user user 53036 aug 24 19:18 tiles-servlet-2.1.3.jar -rw-r--r-- 1 user user 124006 aug 24 19:18 tomcat-jdbc-7.0.42.jar -rw-r--r-- 1 user user 38333 aug 24 19:18 tomcat-juli-7.0.42.jar -rw-r--r-- 1 user user 165092 aug 24 19:18 twilio-java-sdk-3.4.5.jar -rw-r--r-- 1 user user 40 aug 22 02:31 twilio-java-sdk-3.4.5.jar.sha1 -rw-r--r-- 1 user user 5113 aug 22 02:31 twilio-java-sdk-3.4.5.pom -rw-r--r-- 1 user user 40 aug 22 02:31 twilio-java-sdk-3.4.5.pom.sha1 -rw-r--r-- 1 user user 129098 aug 22 02:31 twilio-java-sdk-3.4.5-sources.jar -rw-r--r-- 1 user user 40 aug 22 02:31 twilio-java-sdk-3.4.5-sources.jar.sha1 -rw-r--r-- 1 user user 134530 aug 24 19:18 usertype.core-3.1.0.cr8.jar -rw-r--r-- 1 user user 53688 aug 24 19:18 usertype.spi-3.1.0.cr8.jar -rw-r--r-- 1 user user 47433 aug 24 19:18 validation-api-1.0.0.ga.jar
i checked see if contents of folders in above ls -al
of dependencies had contents, got following results, seem indicate empty:
[user@domain dependencies]$ cd /home/user/javacode/dependencies/1.2/ [user@domain 1.2]$ ls -al total 12 drwxrwxr-x 2 user user 6 aug 22 05:05 . drwxrwxr-x 5 user user 8192 aug 24 19:18 .. [user@domain 1.2]$ cd /home/user/javacode/dependencies/3.4.5/ [user@domain 3.4.5]$ ls -al total 12 drwxr-xr-x 2 user user 6 aug 22 03:00 . drwxrwxr-x 5 user user 8192 aug 24 19:18 .. [user@domain 3.4.5]$ cd /home/user/javacode/dependencies/4.2.3/ [user@domain 4.2.3]$ ls -al total 12 drwxr-xr-x 2 user user 6 aug 22 03:01 . drwxrwxr-x 5 user user 8192 aug 24 19:18 .. [user@domain 4.2.3]$
so how resolve error , program run command line?
answer:
the solution navigate terminal dependencies
directory , type following 4 commands before trying run java code command line again:
rm httpclient-4.2.3.pom rm httpclient-4.2.3.pom.sha1 rm httpclient-4.2.3.jar rm httpclient-4.2.3.jar.sha1
a user hinted @ guess in general direction below, marking accepted answer. actual solution 4 lines of rm commands, eliminated redundant httpclient
libraries.
if nosuchfielderror
@ runtime, explanation different version of @ least 1 class presented @ run time presented @ compile time, and class trying use references field of compile-time version of changed class not present in runtime version of same class.
it difficult judge incompatibility lies, first guess incompatible versions of httpclient , httpcore. note although have 1 version of latter, have 2 versions of former. suppose it's httpclient , httpcore matching version numbers ones intended work together.
Comments
Post a Comment