java - Retrofit + GSON + OkHttp + Okio libraries, no build errors, program doesn't work -
my program doesn't have build error, works in android studio, in eclipse results error. have included libraries needs retrofit
, gson
, okhttp
, okio
.jars. tried searching errors in logcat though, no luck.. maybe of knows answer..
xml layout
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.checkaidev1.mainactivity" > <edittext android:id="@+id/email" android:layout_width="match_parent" android:layout_height="35dp" android:layout_marginend="20dp" android:layout_marginleft="20dp" android:layout_marginright="20dp" android:layout_marginstart="20dp" android:layout_margintop="20dp" android:ems="10" android:inputtype="textemailaddress" android:paddingleft="10dp" android:paddingright="10dp" android:textsize="13sp" android:typeface="sans" android:hint="@string/email" /> <edittext android:id="@+id/confirm_password" android:layout_width="match_parent" android:layout_height="35dp" android:layout_marginend="20dp" android:layout_marginleft="20dp" android:layout_marginright="20dp" android:layout_marginstart="20dp" android:layout_margintop="20dp" android:ems="10" android:inputtype="text" android:paddingleft="10dp" android:paddingright="10dp" android:textsize="13sp" android:typeface="sans" android:hint="@string/password" /> <edittext android:id="@+id/password" android:layout_width="match_parent" android:layout_height="35dp" android:layout_gravity="center_horizontal" android:layout_marginend="20dp" android:layout_marginleft="20dp" android:layout_marginright="20dp" android:layout_marginstart="20dp" android:layout_margintop="20dp" android:inputtype="text" android:paddingleft="10dp" android:paddingright="10dp" android:typeface="sans" android:textsize="13sp" android:hint="@string/confirm_password" /> <button android:id="@+id/sign_in_button" android:layout_width="match_parent" android:layout_height="35dp" android:layout_gravity="center_horizontal" android:layout_margintop="20dp" android:layout_marginleft="20dp" android:layout_marginstart="20dp" android:layout_marginright="20dp" android:layout_marginend="20dp" android:text="@string/sign_in" android:textcolor="#ffffff" android:textsize="13sp" /> <button android:id="@+id/register_button" android:layout_width="match_parent" android:layout_height="35dp" android:layout_gravity="center_horizontal" android:layout_margintop="20dp" android:layout_marginleft="20dp" android:layout_marginstart="20dp" android:layout_marginright="20dp" android:layout_marginend="20dp" android:text="@string/register" android:textcolor="#ffffff" android:textsize="13sp" /> <button android:id="@+id/insert_exam_item_button" android:layout_width="match_parent" android:layout_height="35dp" android:layout_gravity="center_horizontal" android:layout_margintop="20dp" android:layout_marginleft="20dp" android:layout_marginstart="20dp" android:layout_marginright="20dp" android:layout_marginend="20dp" android:text="@string/insert_exam_item" android:textcolor="#ffffff" android:textsize="13sp" /> <button android:id="@+id/get_exam_item_button" android:layout_width="match_parent" android:layout_height="35dp" android:layout_gravity="center_horizontal" android:layout_margintop="20dp" android:layout_marginleft="20dp" android:layout_marginstart="20dp" android:layout_marginright="20dp" android:layout_marginend="20dp" android:text="@string/get_exam_item" android:textcolor="#ffffff" android:textsize="13sp" /></linearlayout>
here controller.java
package com.retrofit; import java.util.arraylist; import java.util.list; import retrofit.callback; import retrofit.restadapter; import retrofit.converter.gsonconverter; import retrofit.http.body; import retrofit.http.field; import retrofit.http.formurlencoded; import retrofit.http.get; import retrofit.http.headers; import retrofit.http.post; import com.google.gson.gson; import com.google.gson.annotations.expose; import com.google.gson.annotations.serializedname; public class checkaidecontroller { private restadapter mrestadapter; private checkaideinterface mcheckaideinterface; public checkaidecontroller() { mrestadapter = new restadapter.builder() .setconverter(new gsonconverter(new gson())) .setendpoint("http://checkaideapi.azurewebsites.net") .setloglevel(restadapter.loglevel.full) .build(); mcheckaideinterface = mrestadapter.create(checkaideinterface.class); } public void signin(string email, string password, callback<signinobject> callback) { mcheckaideinterface.signin("password", email, password, callback); } public void register(registerobject registerobject, callback<successobject> callback) { mcheckaideinterface.register(registerobject, callback); } public void insertexamitem(examitemobject examitemobject, callback<successobject> callback) { mcheckaideinterface.insertexamitem(examitemobject, callback); } public void getexamitemobjects(callback<list<examitemobject>> callback) { mcheckaideinterface.getexamitemobjects(callback); } interface checkaideinterface { @formurlencoded @post("/token") void signin( //concat "=password" @field("grant_type") string granttype, @field("username") string email, @field("password") string password, callback<signinobject> successobjectcallback); @headers("content-type: application/json") @post("/api/account/register") void register( @body registerobject registerobject, callback<successobject> successobjectcallback); @headers({ "content-type: application/json", "authorization: bearer 4dbcwj-iwe4c4o8xiyey5lie8plfnbmshqfkrew3v9giqlavfnjpbzryu2xgrx2k1ealamku4x-bmylca4goktdjlwjei_ivqb7wwpu7hn7ef3ifpvthfptgbv2sqb1_yjustotlev8idr491ligyf74lzibubh9-ionmpksvtg5e3fpoyh1kd7dkhwrwpv5ghmo1akqf3meoi4kyuhpdh6wyxzlr4_-gsjj8zwsotio6vsvpc0s7glp9wjwbogn__sa3mcs0fz2mslsevwpcyjwrtxqworiv_9naqpukw94xkguwuz3st0zpqdfxesxsguduedeebo018qxvvexhyoltloevy330fwzlia_hp-s8rsih9jxrelcdesuzvcvggogcmixq8azkzu95wntp9p72i0cqfscolwtjbp_rzkwmvj8--v8azwozkr6gog2li91beitujcm3j3qi64ller8yea9sf9463h-rfg1gyj8xjf6m-1cjgv4gwwtzhkh" }) @post("/api/exam/insertexam") void insertexamitem( @body examitemobject examitemobject, callback<successobject> successobjectcallback); @headers({ "content-type: application/json", "authorization: bearer 4dbcwj-iwe4c4o8xiyey5lie8plfnbmshqfkrew3v9giqlavfnjpbzryu2xgrx2k1ealamku4x-bmylca4goktdjlwjei_ivqb7wwpu7hn7ef3ifpvthfptgbv2sqb1_yjustotlev8idr491ligyf74lzibubh9-ionmpksvtg5e3fpoyh1kd7dkhwrwpv5ghmo1akqf3meoi4kyuhpdh6wyxzlr4_-gsjj8zwsotio6vsvpc0s7glp9wjwbogn__sa3mcs0fz2mslsevwpcyjwrtxqworiv_9naqpukw94xkguwuz3st0zpqdfxesxsguduedeebo018qxvvexhyoltloevy330fwzlia_hp-s8rsih9jxrelcdesuzvcvggogcmixq8azkzu95wntp9p72i0cqfscolwtjbp_rzkwmvj8--v8azwozkr6gog2li91beitujcm3j3qi64ller8yea9sf9463h-rfg1gyj8xjf6m-1cjgv4gwwtzhkh" }) @get("/api/exam/getexam") void getexamitemobjects( callback<list<examitemobject>> successobjectcallback); } public class successobject { @expose private string success; public string getsuccess() { return success; } public void setsuccess(string success) { this.success = success; } } public class signinobject { @expose @serializedname("access_token") private string accesstoken; @expose @serializedname("token_type") private string tokentype; @expose @serializedname("expires_in") private double expiresin; @expose private string username; @expose @serializedname(".issued") private string issued; @expose @serializedname(".expires") private string expires; public string getaccesstoken() { return accesstoken; } public void setaccesstoken(string accesstoken) { this.accesstoken = accesstoken; } public string gettokentype() { return tokentype; } public void settokentype(string tokentype) { this.tokentype = tokentype; } public double getexpiresin() { return expiresin; } public void setexpiresin(double expiresin) { this.expiresin = expiresin; } public string getusername() { return username; } public void setusername(string username) { this.username = username; } public string getissued() { return issued; } public void setissued(string issued) { this.issued = issued; } public string getexpires() { return expires; } public void setexpires(string expires) { this.expires = expires; } } public class registerobject { @expose @serializedname("email") private string email; @expose @serializedname("password") private string password; @expose @serializedname("confirmpassword") private string confirmpassword; public string getemail() { return email; } public void setemail(string email) { this.email = email; } public string getpassword() { return password; } public void setpassword(string password) { this.password = password; } public string getconfirmpassword() { return confirmpassword; } public void setconfirmpassword(string confirmpassword) { this.confirmpassword = confirmpassword; } } public class examitemobject { @expose @serializedname("examname") private string examname; @expose @serializedname("itemnumber") private string itemnumber; @expose @serializedname("correctkey") private string correctkey; @expose @serializedname("itemcategory") private string itemcategory; @expose @serializedname("results") private list<itemobject> results = new arraylist<>(); public string getexamname() { return examname; } public void setexamname(string examname) { this.examname = examname; } public string getitemnumber() { return itemnumber; } public void setitemnumber(string itemnumber) { this.itemnumber = itemnumber; } public string getcorrectkey() { return correctkey; } public void setcorrectkey(string correctkey) { this.correctkey = correctkey; } public string getitemcategory() { return itemcategory; } public void setitemcategory(string itemcategory) { this.itemcategory = itemcategory; } public list<itemobject> getresults() { return results; } public void setresults(list<itemobject> results) { this.results = results; } } public class itemobject { @expose @serializedname("studentid") private string studentid; @expose @serializedname("answeredkey") private string answeredkey; public string getstudentid() { return studentid; } public void setstudentid(string studentid) { this.studentid = studentid; } public string getansweredkey() { return answeredkey; } public void setansweredkey(string answeredkey) { this.answeredkey = answeredkey; } } }
it's simple log-in , registration page.. according layout , mainactivity.java
package com.retrofit; import java.util.arraylist; import java.util.list; import retrofit.callback; import retrofit.retrofiterror; import retrofit.client.response; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.toast; public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); final checkaidecontroller checkaidecontroller = new checkaidecontroller(); button signinbutton = (button) findviewbyid(r.id.sign_in_button); signinbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { checkaidecontroller.signin("dennisintal@gmail.com", "p@$$w0rd", new callback<checkaidecontroller.signinobject>() { @override public void success(checkaidecontroller.signinobject signinobject, response response) { toast.maketext(getapplicationcontext(), "success", toast.length_long).show(); } @override public void failure(retrofiterror error) { toast.maketext(getapplicationcontext(), "failure", toast.length_long).show(); } }); } }); final edittext emailedittext = (edittext) findviewbyid(r.id.email); final edittext passwordedittext = (edittext) findviewbyid(r.id.password); final edittext confirmpasswordedittext = (edittext) findviewbyid(r.id.confirm_password); final button registerbutton = (button) findviewbyid(r.id.register_button); registerbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { checkaidecontroller.registerobject registerobject = checkaidecontroller.new registerobject(); registerobject.setemail(emailedittext.gettext().tostring()); registerobject.setpassword(passwordedittext.gettext().tostring()); registerobject.setconfirmpassword(confirmpasswordedittext.gettext().tostring()); checkaidecontroller.register( registerobject, new callback<checkaidecontroller.successobject>() { @override public void success(checkaidecontroller.successobject successobject, response response) { toast.maketext(getapplicationcontext(), "register success", toast.length_long).show(); } @override public void failure(retrofiterror error) { toast.maketext(getapplicationcontext(), "register failure", toast.length_long).show(); } }); } }); final button insertexamitembutton = (button) findviewbyid(r.id.insert_exam_item_button); insertexamitembutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { checkaidecontroller.examitemobject examitemobject = checkaidecontroller.new examitemobject(); examitemobject.setexamname("android exam"); examitemobject.setitemnumber("1"); examitemobject.setcorrectkey("a"); examitemobject.setitemcategory("some category"); list<checkaidecontroller.itemobject> resultlist = new arraylist<checkaidecontroller.itemobject>(); checkaidecontroller.itemobject itemobject1 = checkaidecontroller.new itemobject(); itemobject1.setstudentid("1"); itemobject1.setansweredkey("c"); checkaidecontroller.itemobject itemobject2 = checkaidecontroller.new itemobject(); itemobject2.setstudentid("2"); itemobject2.setansweredkey("a"); resultlist.add(itemobject1); resultlist.add(itemobject2); examitemobject.setresults(resultlist); checkaidecontroller.insertexamitem(examitemobject, new callback<checkaidecontroller.successobject>() { @override public void success(checkaidecontroller.successobject successobject, response response) { toast.maketext(getapplicationcontext(), "insert success", toast.length_long).show(); } @override public void failure(retrofiterror error) { toast.maketext(getapplicationcontext(), "insert failure", toast.length_long).show(); } }); } }); final button getexamitembutton = (button) findviewbyid(r.id.get_exam_item_button); getexamitembutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { checkaidecontroller.getexamitemobjects(new callback<list<checkaidecontroller.examitemobject>>() { @override public void success(list<checkaidecontroller.examitemobject> examitemobjects, response response) { toast.maketext(getapplicationcontext(), "get success", toast.length_long).show(); } @override public void failure(retrofiterror error) { toast.maketext(getapplicationcontext(), "get failure", toast.length_long).show(); } }); } }); } }
the manifest contains permissions
<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" />
logcat:
10-22 20:55:15.815: i/dalvikvm(25530): not find method okio.source.close, referenced method com.squareup.okhttp.internal.http.socketconnector.createtunnel 10-22 20:55:15.815: w/dalvikvm(25530): vfy: unable resolve interface method 11863: lokio/source;.close ()v 10-22 20:55:15.815: d/dalvikvm(25530): vfy: replacing opcode 0x72 @ 0x007b 10-22 20:55:15.825: e/dalvikvm(25530): not find class 'okio.buffer', referenced method com.squareup.okhttp.internal.platform.concatlengthprefixed 10-22 20:55:15.825: w/dalvikvm(25530): vfy: unable resolve new-instance 1604 (lokio/buffer;) in lcom/squareup/okhttp/internal/platform; 10-22 20:55:15.825: d/dalvikvm(25530): vfy: replacing opcode 0x22 @ 0x0000 10-22 20:55:15.835: d/dalvikvm(25530): dexopt: unable opt direct call 0x2dfc @ 0x02 in lcom/squareup/okhttp/internal/platform;.concatlengthprefixed 10-22 20:55:16.135: i/dalvikvm(25530): not find method okio.okio.source, referenced method com.squareup.okhttp.internal.http.httpconnection.<init> 10-22 20:55:16.135: w/dalvikvm(25530): vfy: unable resolve static method 11860: lokio/okio;.source (ljava/net/socket;)lokio/source; 10-22 20:55:16.135: d/dalvikvm(25530): vfy: replacing opcode 0x71 @ 0x000e 10-22 20:55:16.140: w/dalvikvm(25530): vfy: unable find class referenced in signature (lokio/bufferedsink;) 10-22 20:55:16.145: w/dalvikvm(25530): vfy: unable find class referenced in signature (lokio/forwardingtimeout;) 10-22 20:55:16.145: w/dalvikvm(25530): vfy: unable find class referenced in signature (lokio/forwardingtimeout;) 10-22 20:55:16.145: w/dalvikvm(25530): vfy: unable find class referenced in signature (lokio/bufferedsource;) 10-22 20:55:16.150: w/dalvikvm(25530): vfy: unable find class referenced in signature (lokio/forwardingtimeout;) 10-22 20:55:16.150: i/dalvikvm(25530): not find method okio.forwardingtimeout.delegate, referenced method com.squareup.okhttp.internal.http.httpconnection.detachtimeout 10-22 20:55:16.150: w/dalvikvm(25530): vfy: unable resolve virtual method 11849: lokio/forwardingtimeout;.delegate ()lokio/timeout; 10-22 20:55:16.150: d/dalvikvm(25530): vfy: replacing opcode 0x6e @ 0x0000 10-22 20:55:16.160: i/dalvikvm(25530): not find method okio.bufferedsource.buffer, referenced method com.squareup.okhttp.internal.http.httpconnection.buffersize 10-22 20:55:16.160: w/dalvikvm(25530): vfy: unable resolve interface method 11811: lokio/bufferedsource;.buffer ()lokio/buffer; 10-22 20:55:16.160: d/dalvikvm(25530): vfy: replacing opcode 0x72 @ 0x0002 10-22 20:55:16.165: i/dalvikvm(25530): not find method okio.bufferedsink.flush, referenced method com.squareup.okhttp.internal.http.httpconnection.flush 10-22 20:55:16.165: w/dalvikvm(25530): vfy: unable resolve interface method 11797: lokio/bufferedsink;.flush ()v 10-22 20:55:16.165: d/dalvikvm(25530): vfy: replacing opcode 0x72 @ 0x0002 10-22 20:55:16.175: i/dalvikvm(25530): not find method okio.bufferedsource.exhausted, referenced method com.squareup.okhttp.internal.http.httpconnection.isreadable 10-22 20:55:16.175: w/dalvikvm(25530): vfy: unable resolve interface method 11813: lokio/bufferedsource;.exhausted ()z 10-22 20:55:16.175: d/dalvikvm(25530): vfy: replacing opcode 0x72 @ 0x0010 10-22 20:55:16.185: i/dalvikvm(25530): failed resolving lcom/squareup/okhttp/internal/http/httpconnection$chunkedsink; interface 1615 'lokio/sink;' 10-22 20:55:16.185: w/dalvikvm(25530): link of class 'lcom/squareup/okhttp/internal/http/httpconnection$chunkedsink;' failed 10-22 20:55:16.185: e/dalvikvm(25530): not find class 'com.squareup.okhttp.internal.http.httpconnection$chunkedsink', referenced method com.squareup.okhttp.internal.http.httpconnection.newchunkedsink 10-22 20:55:16.185: w/dalvikvm(25530): vfy: unable resolve new-instance 1297 (lcom/squareup/okhttp/internal/http/httpconnection$chunkedsink;) in lcom/squareup/okhttp/internal/http/httpconnection; 10-22 20:55:16.185: d/dalvikvm(25530): vfy: replacing opcode 0x22 @ 0x0023 10-22 20:55:16.190: i/dalvikvm(25530): failed resolving lcom/squareup/okhttp/internal/http/httpconnection$abstractsource; interface 1616 'lokio/source;' 10-22 20:55:16.190: w/dalvikvm(25530): link of class 'lcom/squareup/okhttp/internal/http/httpconnection$abstractsource;' failed 10-22 20:55:16.190: w/dalvikvm(25530): unable resolve superclass of lcom/squareup/okhttp/internal/http/httpconnection$chunkedsource; (1296) 10-22 20:55:16.190: w/dalvikvm(25530): link of class 'lcom/squareup/okhttp/internal/http/httpconnection$chunkedsource;' failed 10-22 20:55:16.195: e/dalvikvm(25530): not find class 'com.squareup.okhttp.internal.http.httpconnection$chunkedsource', referenced method com.squareup.okhttp.internal.http.httpconnection.newchunkedsource 10-22 20:55:16.195: w/dalvikvm(25530): vfy: unable resolve new-instance 1298 (lcom/squareup/okhttp/internal/http/httpconnection$chunkedsource;) in lcom/squareup/okhttp/internal/http/httpconnection; 10-22 20:55:16.195: d/dalvikvm(25530): vfy: replacing opcode 0x22 @ 0x0023 10-22 20:55:16.195: i/dalvikvm(25530): failed resolving lcom/squareup/okhttp/internal/http/httpconnection$fixedlengthsink; interface 1615 'lokio/sink;' 10-22 20:55:16.195: w/dalvikvm(25530): link of class 'lcom/squareup/okhttp/internal/http/httpconnection$fixedlengthsink;' failed 10-22 20:55:16.195: e/dalvikvm(25530): not find class 'com.squareup.okhttp.internal.http.httpconnection$fixedlengthsink', referenced method com.squareup.okhttp.internal.http.httpconnection.newfixedlengthsink 10-22 20:55:16.195: w/dalvikvm(25530): vfy: unable resolve new-instance 1299 (lcom/squareup/okhttp/internal/http/httpconnection$fixedlengthsink;) in lcom/squareup/okhttp/internal/http/httpconnection; 10-22 20:55:16.195: d/dalvikvm(25530): vfy: replacing opcode 0x22 @ 0x0023 10-22 20:55:16.200: i/dalvikvm(25530): failed resolving lcom/squareup/okhttp/internal/http/httpconnection$abstractsource; interface 1616 'lokio/source;' 10-22 20:55:16.200: w/dalvikvm(25530): link of class 'lcom/squareup/okhttp/internal/http/httpconnection$abstractsource;' failed 10-22 20:55:16.200: w/dalvikvm(25530): unable resolve superclass of lcom/squareup/okhttp/internal/http/httpconnection$fixedlengthsource; (1296) 10-22 20:55:16.200: w/dalvikvm(25530): link of class 'lcom/squareup/okhttp/internal/http/httpconnection$fixedlengthsource;' failed 10-22 20:55:16.200: e/dalvikvm(25530): not find class 'com.squareup.okhttp.internal.http.httpconnection$fixedlengthsource', referenced method com.squareup.okhttp.internal.http.httpconnection.newfixedlengthsource
Comments
Post a Comment