java - Configuring Braintree -


i trying accept braintree on app. don't understand async http client part.

where place in app? currently, have in mainactivity , giving me errors 'get', 'texthttpresponsehandler' 'clienttoken'.

any ideas?

package com.example.android.payments;  import android.content.intent; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import com.loopj.android.http.*; import com.braintreepayments.api.dropin.braintreepaymentactivity;   public class mainactivity extends actionbaractivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);      }     asynchttpclient client = new asynchttpclient();     client.get("https://your-server/client_token", new texthttpresponsehandler() {         @override         public void onsuccess(string clienttoken) {             this.clienttoken = clienttoken;         }     });     public void onbraintreesubmit(view v) {         intent intent = new intent(context, braintreepaymentactivity.class);         intent.putextra(braintreepaymentactivity.extra_client_token, clienttoken);         // request_code arbitrary , used within activity.         startactivityforresult(intent, request_code);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_main, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     } } 

your call client.get() not in method body, code not syntactically valid. try putting in method (or constructor or initializer block - it's bad idea work in either of places).

for example, put statement in new method called fetchclienttoken():

public class mainactivity extends actionbaractivity {      @override     protected void oncreate(bundle savedinstancestate) { ... }      asynchttpclient client = new asynchttpclient();      public void fetchclienttoken() {       client.get("https://your-server/client_token", new texthttpresponsehandler() {           @override           public void onsuccess(string clienttoken) {               this.clienttoken = clienttoken;           }       });     }      public void onbraintreesubmit(view v) { ... }     @override public boolean oncreateoptionsmenu(menu menu) { ... }     @override public boolean onoptionsitemselected(menuitem item) { ... } } 

you need invoke fetchclienttoken somehow, other method.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -