Guest User

Untitled

a guest
Mar 14th, 2018
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.activity_main);
  7.  
  8. try{
  9. UserAgent userAgent = new UserAgent();
  10. userAgent.visit("http://jaunt-api.com/examples/signup.htm");
  11. ///Document doc = userAgent.doc;
  12.  
  13. ///doc.fillout("E-mail:", "tom@mail.com"); //fill out the (textfield) component labelled "E-mail:"
  14. ///doc.choose("Account Type:", "advanced"); //choose "advanced" from the menu labelled "Account Type:"
  15. ///doc.fillout("Comments:", "no comment"); //fill out the (textarea) component labelled "Comments:"
  16. ////doc.choose(Label.RIGHT, "No thanks"); //choose the (radiobutton) component right-labelled "No thanks"
  17. ////doc.submit("create trial account"); //press the submit button labelled 'create trial account'
  18. ///System.out.println(userAgent.getLocation()); //print the current location (url)
  19. }
  20. catch(JauntException e){
  21. System.out.println(e);
  22. }
  23.  
  24. }
  25.  
  26. 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
  27.  
  28. try{
  29. UserAgent userAgent = new UserAgent();
  30. userAgent.visit("http://jaunt-api.com/examples/signup.htm");
  31.  
  32. userAgent.doc.apply( //fill-out the form by applying a sequence of inputs
  33. "tom@mail.com", //string input is applied to textfield
  34. "(advanced)", //bracketed string (regular expression) selects a menu item
  35. "no comment", //string input is applied to textarea
  36. 1 //integer specifies index of radiobutton choice
  37. );
  38. userAgent.doc.submit("create trial account"); //press the submit button labelled 'create trial account'
  39. System.out.println(userAgent.getLocation()); //print the current location (url)
  40. }
  41. catch(JauntException e){
  42. System.out.println(e);
  43. }
  44.  
  45. <manifest xlmns:android...>
  46. ...
  47. <uses-permission android:name="android.permission.INTERNET" />
  48. <application ...
  49. </manifest>
  50.  
  51. private class OkHttpHandler extends AsyncTask<String, Void, byte[]> {
  52.  
  53.  
  54.  
  55. @Override
  56. protected byte[] doInBackground(String... params) {
  57.  
  58. UserAgent userAgent = new UserAgent();
  59. userAgent.visit("http://jaunt-api.com/examples/signup.htm");
  60.  
  61. return null;
  62. }
  63.  
  64. @Override
  65. protected void onPostExecute(byte[] bytes) {
  66. super.onPostExecute(bytes);
  67.  
  68. try{
  69.  
  70. Form form = userAgent.doc.getForm(0); //get the document's first Form
  71. form.setTextField("email", "tom@mail.com"); //or form.set("email", "tom@mail.com");
  72. form.setPassword("pw", "secret"); //or form.set("pw", "secret");
  73. form.setCheckBox("remember", true); //or form.set("remember", "on");
  74. form.setSelect("account", "advanced"); //or form.set("account", "advanced");
  75. form.setTextArea("comment", "no comment"); //or form.set("comment", "no comment");
  76. form.setRadio("inform", "no"); //or form.set("inform", "no");
  77. form.submit("create trial account"); //click the submit button labelled 'create trial account'
  78. System.out.println(userAgent.getLocation());//print the current location (url)
  79. }
  80. catch(JauntException e){
  81. System.err.println(e);
  82. }
  83.  
  84. }
  85. }
  86.  
  87. new OkHttpHandler().execute();
Add Comment
Please, Sign In to add comment