Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- try{
- UserAgent userAgent = new UserAgent();
- userAgent.visit("http://jaunt-api.com/examples/signup.htm");
- ///Document doc = userAgent.doc;
- ///doc.fillout("E-mail:", "tom@mail.com"); //fill out the (textfield) component labelled "E-mail:"
- ///doc.choose("Account Type:", "advanced"); //choose "advanced" from the menu labelled "Account Type:"
- ///doc.fillout("Comments:", "no comment"); //fill out the (textarea) component labelled "Comments:"
- ////doc.choose(Label.RIGHT, "No thanks"); //choose the (radiobutton) component right-labelled "No thanks"
- ////doc.submit("create trial account"); //press the submit button labelled 'create trial account'
- ///System.out.println(userAgent.getLocation()); //print the current location (url)
- }
- catch(JauntException e){
- System.out.println(e);
- }
- }
- java.lang.NullPointerException: Attempt to invoke interface method 'void com.android.okhttp.internal.http.Transport.writeRequestHeaders(com.android.okhttp.Request)' on a null object reference
- try{
- UserAgent userAgent = new UserAgent();
- userAgent.visit("http://jaunt-api.com/examples/signup.htm");
- userAgent.doc.apply( //fill-out the form by applying a sequence of inputs
- "tom@mail.com", //string input is applied to textfield
- "(advanced)", //bracketed string (regular expression) selects a menu item
- "no comment", //string input is applied to textarea
- 1 //integer specifies index of radiobutton choice
- );
- userAgent.doc.submit("create trial account"); //press the submit button labelled 'create trial account'
- System.out.println(userAgent.getLocation()); //print the current location (url)
- }
- catch(JauntException e){
- System.out.println(e);
- }
- <manifest xlmns:android...>
- ...
- <uses-permission android:name="android.permission.INTERNET" />
- <application ...
- </manifest>
- private class OkHttpHandler extends AsyncTask<String, Void, byte[]> {
- @Override
- protected byte[] doInBackground(String... params) {
- UserAgent userAgent = new UserAgent();
- userAgent.visit("http://jaunt-api.com/examples/signup.htm");
- return null;
- }
- @Override
- protected void onPostExecute(byte[] bytes) {
- super.onPostExecute(bytes);
- try{
- Form form = userAgent.doc.getForm(0); //get the document's first Form
- form.setTextField("email", "tom@mail.com"); //or form.set("email", "tom@mail.com");
- form.setPassword("pw", "secret"); //or form.set("pw", "secret");
- form.setCheckBox("remember", true); //or form.set("remember", "on");
- form.setSelect("account", "advanced"); //or form.set("account", "advanced");
- form.setTextArea("comment", "no comment"); //or form.set("comment", "no comment");
- form.setRadio("inform", "no"); //or form.set("inform", "no");
- form.submit("create trial account"); //click the submit button labelled 'create trial account'
- System.out.println(userAgent.getLocation());//print the current location (url)
- }
- catch(JauntException e){
- System.err.println(e);
- }
- }
- }
- new OkHttpHandler().execute();
Add Comment
Please, Sign In to add comment