converting a java code into an android application
<p>i have got a java code for a oAuth login in the Indivo server. It is working good when I'm running it from the terminal. Now, I would like to convert it to an Android app, doing pretty much the same thing. What are the necessary changes that I need to incorporate, in order to convert this raw java code into a running Android application?</p>

<p>When I copy the same code, and import the necessary packages, it gives an error in the class definition, and in the main declaration. it says "the main method cannot be declared static".</p>

<p>Here is the java code:</p>

<p>public class ChromeTest {</p>

<pre><code>                private Map&lt;String, Object&gt; options = null;
                private String recordId = null;
                private String recordId_second = null;
                private String appId = "chrome@apps.indivo.org";
                private String problemApp = "problems@apps.indivo.org";
                private Properties properties = null;
                private String sessionToken = null;
                private String sessionTokenSecret = null;
                private String sessionToken_second = null;
                private String sessionTokenSecret_second = null;
                private String pagingOrderingQuery = null;
                private String extrnlRandom = null;

                private XPath xpath = null;

                private DatatypeFactory dtf = null;
                private XMLGregorianCalendar gregCal = null;

                private String demographicsDoc =
            "&lt;Demographics xmlns=\"Demographics\"&gt;"
            + "&lt;dateOfBirth&gt;2009-11-02T00:40:30+00:00&lt;/dateOfBirth&gt;"
            + "&lt;/Demographics&gt;";

                private String contactDoc =
            "&lt;Contact  xmlns=\"Contact\"&gt;"
            + "&lt;name&gt;&lt;fullname&gt;nameForTestDocument&lt;/fullname&gt;&lt;givenName/&gt;&lt;familyName/&gt;&lt;/name&gt;"
            + "&lt;email type=\"work\"&gt;nathan.finstein@childrens.harvard.edu&lt;/email&gt;"
            + "&lt;address type=\"home\"&gt;&lt;streetAddress&gt;1 one way&lt;/streetAddress&gt;"
            + "&lt;postalCode&gt;12345&lt;/postalCode&gt;"
            + "&lt;locality&gt;ames&lt;/locality&gt;"
            + "&lt;region&gt;Colorado&lt;/region&gt;"
            + "&lt;country&gt;USA&lt;/country&gt;&lt;/address&gt;"
            + "&lt;location type=\"home\"&gt;&lt;latitude&gt;90&lt;/latitude&gt;&lt;longitude&gt;90&lt;/longitude&gt;&lt;/location&gt;"
            + "&lt;/Contact&gt;";

                String testDocExtrnl = "&lt;Testing123&gt;strictly for testing - external from chrome&lt;/Testing123&gt;";
                String testDocStatus = "&lt;Testing123&gt;strictly for testing Status from chrome&lt;/Testing123&gt;";
                String testDocRelate_A = "&lt;Testing123&gt;strictly for testing Relate from chrome A&lt;/Testing123&gt;";
                String testDocRelate_B = "&lt;Testing123&gt;strictly for testing Relate from chrome B&lt;/Testing123&gt;";
                String testDocAppSpecific = "&lt;Testing123&gt;strictly for testing - app specific from chrome&lt;/Testing123&gt;";
                String testDocAppSpecificR = "&lt;Testing123&gt;strictly for testing - app specific record specific from chrome&lt;/Testing123&gt;";
                String testDoc = "&lt;Testing123&gt;strictly for testing - chrome created no externalID&lt;/Testing123&gt;";
                //String testDocRplc = "&lt;Testing123&gt;strictly for testing - replaced by Chrome&lt;/Testing123&gt;";
                String testDocEstablished = "&lt;Testing123&gt;strictly for testing - Have Chrome try to delete later&lt;/Testing123&gt;";
                String testDocToDelete = "&lt;Testing123&gt;strictly for testing - Chrome should be able to delete this if done soon&lt;/Testing123&gt;";
                String testDocToReplace = "&lt;Testing123&gt;strictly for testing - Chrome will replace this version&lt;/Testing123&gt;";
                String testDocReplacement = "&lt;Testing123&gt;strictly for testing - Chrome will use this to replace the other&lt;/Testing123&gt;";
                String testDocToShare = "&lt;Testing123&gt;share this&lt;/Testing123&gt;";

                String allergyDoc =
            "&lt;Allergy xmlns=\"http://indivo.org/vocab/xml/documents#\"&gt;\n" +
            "  &lt;dateDiagnosed&gt;2009-05-16&lt;/dateDiagnosed&gt;\n" +
            "  &lt;diagnosedBy&gt;Children's Hospital Boston&lt;/diagnosedBy&gt;\n" +
            "  &lt;allergen&gt;\n" +
            "    &lt;type type=\"http://codes.indivo.org/codes/allergentypes/\" value=\"drugs\"&gt;Drugs&lt;/type&gt;\n" +
            "    &lt;name type=\"http://codes.indivo.org/codes/allergens/\" value=\"penicillin\"&gt;Penicillin&lt;/name&gt;\n" +
            "  &lt;/allergen&gt;\n\n" +
            "  &lt;reaction&gt;blue rash&lt;/reaction&gt;\n" +
            "  &lt;specifics&gt;this only happens on weekends&lt;/specifics&gt;\n" +
            "&lt;/Allergy&gt;";


                String medicationDoc =
            "&lt;Medication xmlns=\"http://indivo.org/vocab/xml/documents#\"&gt;" +
              "&lt;dateStarted&gt;2009-02-05&lt;/dateStarted&gt;" +
              "&lt;name type=\"http://indivo.org/codes/meds#\" abbrev=\"c2i\" value=\"cox2-inhibitor\"&gt;COX2 Inhibitor&lt;/name&gt;" +
              "&lt;brandName type=\"http://indivo.org/codes/meds#\" abbrev=\"vioxx\" value=\"Vioxx\"&gt;Vioxx&lt;/brandName&gt;" +
              "&lt;dose&gt;&lt;value&gt;3&lt;/value&gt;&lt;unit type=\"http://indivo.org/codes/units#\" value=\"pills\" abbrev=\"p\"&gt;pills&lt;/unit&gt;&lt;/dose&gt;" +
              "&lt;route type=\"http://indivo.org/codes/routes#\" value=\"PO\"&gt;By Mouth&lt;/route&gt;" +
              "&lt;strength&gt;&lt;value&gt;100&lt;/value&gt;&lt;unit type=\"http://indivo.org/codes/units#\" value=\"mg\" abbrev=\"mg\"&gt;milligram&lt;/unit&gt;&lt;/strength&gt;" +
              "&lt;frequency type=\"http://indivo.org/codes/frequency#\" value=\"daily\"&gt;daily&lt;/frequency&gt;" +
              "&lt;/Medication&gt;";


                /**
                 * @param args the command line arguments
                 */
                public static void main(String[] args) throws
                IndivoClientException, IOException, XPathExpressionException, javax.xml.datatype.DatatypeConfigurationException{
                    // TODO code application logic here
                    ChromeTest instance = new ChromeTest();

                    Properties props = new Properties();
                    instance.properties = props;

                    instance.xpath = XPathFactory.newInstance().newXPath();
                    instance.extrnlRandom = Integer.toString(new Random().nextInt(1000000));

                    instance.dtf = DatatypeFactory.newInstance();

                    instance.doTest();
                }


                private void reportKnownError(Exception ice) {
                    String errId = Integer.toString(new Random().nextInt(1000000));
                    System.err.println("\n\nerror id: " + errId);

                    ice.printStackTrace();
                    System.err.println("==============================================\n");
                    System.out.println("Known exception thrown, stack trace in error stream, see: " + errId + "\n");

                }

                private void doTest() throws IndivoClientException, XPathExpressionException, UnsupportedEncodingException {
                    Rest chrome = new Rest("chrome", "chrome", "http://localhost:8080", null);
                    String accountId = "johnsmith@example.org";
                    String username = "jsmith";
                    String password = "password.example";


                    String accountId_second = "johnsmith@example.org";
                    String username_second = "jsmith";
                    String password_second = "password.example";

                    recordId = "781a64e7-fc04-4bbc-8804-7480b0b337dc";
                    recordId_second = "781a64e7-fc04-4bbc-8804-7480b0b337dc";


                    String str = "username="+ username+ "&amp;password="+password ;
                    System.out.println("testing -- oauth_internal_session_createPOST");
                    Map&lt;String,String&gt; testResultForm  =(Map&lt;String,String&gt;) chrome.oauth_internal_session_createPOST(str, options);
                    System.out.println("oauth_internal_session_createPOST  once");
                    System.out.println(Utils.printForm(testResultForm) + "\n\n");
                    sessionToken = testResultForm.get("oauth_token");
                    sessionTokenSecret = testResultForm.get("oauth_token_secret");
                    String str1 = "username="+ username_second+ "&amp;password="+password_second ;

                    testResultForm  =(Map&lt;String,String&gt;)chrome.oauth_internal_session_createPOST(str1, options);

                    System.out.println(Utils.printForm(testResultForm) + "\n\n");
                    sessionToken_second = testResultForm.get("oauth_token");
                    sessionTokenSecret_second = testResultForm.get("oauth_token_secret");

                    Document testResultDoc = null;
                    System.out.println("testing -- records_X_documents_X_versions_GET");

                    System.out.println("testing -- records_X_documents_GET");
                    String xmlDateTime = null;
                    gregCal = dtf.newXMLGregorianCalendar(new GregorianCalendar());
                    xmlDateTime = gregCal.toXMLFormat();

                    String hba1cDoc = "&lt;HBA1C xmlns=\"http://indivo.org/vocab#\" value=\"6.3\""
                        + " unit=\"mg/dL\" datetime=\"" + xmlDateTime + "\" /&gt;"; 
                    System.out.println("testing -- records_X_documents_POST");
                    testResultDoc = (Document) chrome.records_X_documents_POST(
                            recordId, sessionToken, sessionTokenSecret, hba1cDoc, "application/xml", options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n--------------------------------------\n\n");
                    System.out.println("testing -- records_X_documents_POST");
                    testResultDoc = (Document) chrome.records_X_documents_POST(
                            recordId, sessionToken, sessionTokenSecret,
                            hba1cDoc.replace("\"6.3\"", "\"7.4\""), "application/xml", options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n--------------------------------------\n\n");


                    testResultDoc = (Document) chrome.records_X_documents_POST(recordId, sessionToken, sessionTokenSecret,
                            medicationDoc,  "application/xml", options);

                    System.out.println("testing -- records_X_reports_minimal_X_GET");
                    testResultDoc = (Document) chrome.records_X_reports_minimal_X_GET(
                            pagingOrderingQuery, recordId, "medications", sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n==================================================\n\n");

                    System.out.println("testing -- accounts_XGET");
                    testResultDoc = (Document) chrome.accounts_XGET(accountId, sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n==================================================\n\n");


                    System.out.println("testing -- accounts_X_infoSetPOST");
                    testResultDoc = (Document) chrome.accounts_X_infoSetPOST(
                            "new full_name nathan.finstein@childrens.harvard.edu", accountId, sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n==================================================\n\n");

                    System.out.println("testing -- accounts_X_authsystems_password_setUsernamePOST");
                    testResultDoc = (Document) chrome.accounts_X_authsystems_password_setUsernamePOST(username + "_new", accountId, sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n------------------------------------------------\n\n");

                    // now set it back right away so we don't break anything
                    System.out.println("testing -- accounts_X_authsystems_password_setUsernamePOST");
                    testResultDoc = (Document) chrome.accounts_X_authsystems_password_setUsernamePOST(username, accountId, sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n------------------------------------------------\n\n");

                    String str2 = "username="+ username+ "&amp;password="+password ;
                    testResultForm  =(Map&lt;String,String&gt;)chrome.oauth_internal_session_createPOST(str2, options);
                    System.out.println("oauth_internal_session_createPOST  twice");
                    System.out.println(Utils.printForm(testResultForm) + "\n\n");
                    sessionToken = testResultForm.get("oauth_token");
                    sessionTokenSecret = testResultForm.get("oauth_token_secret");
                    System.out.println("\n==================================================\n\n");

                    System.out.println("testing -- accounts_X_authsystems_password_changePOST");
                    testResultDoc = (Document) chrome.accounts_X_authsystems_password_changePOST(password, 
                            password + "_new", accountId, sessionToken, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n--------------------------------------------------\n\n");

                    // now change it right back
                    System.out.println("testing -- accounts_X_authsystems_password_changePOST");
                    testResultDoc = (Document) chrome.accounts_X_authsystems_password_changePOST(password + "_new", password, accountId, sessionToken, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n==================================================\n\n");


                    // now set it back to what it was
                    System.out.println("testing -- accounts_X_authsystems_password_setUsernamePOST");
                    try {
                    System.out.println("testing -- records_X_apps_XDELETE");
                    testResultDoc = (Document) chrome.records_X_apps_XDELETE(
                            recordId_second, problemApp, sessionToken_second, sessionTokenSecret_second, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n==================================================\n\n");
                    } catch (IndivoClientException ice) {
                        reportKnownError(ice);
                    }


                    if (false) {  // skip for now, test with OAuth dance
                    System.out.println("testing -- oauth_internal_request_tokens_X_claimPOST");
                    testResultDoc = (Document) chrome.oauth_internal_request_tokens_X_claimPOST("requestToken", sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n==================================================\n\n");

                    System.out.println("testing -- oauth_internal_request_tokens_X_infoGET");
                    testResultDoc = (Document) chrome.oauth_internal_request_tokens_X_infoGET("requestToken", sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n==================================================\n\n");

                    System.out.println("testing -- oauth_internal_request_tokens_X_approvePOST");
                    testResultForm = (Map&lt;String,String&gt;) chrome.oauth_internal_request_tokens_X_approvePOST(recordId, "requestToken",
                            sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.printForm(testResultForm) + "\n\n");
                    System.out.println("\n==================================================\n\n");

                    System.out.println("testing -- oauth_internal_surlVerifyGET");
                    testResultDoc = (Document) chrome.oauth_internal_surlVerifyGET("/widgets/WidgetName?param1=foo&amp;param2=bar&amp;surl_timestamp=&lt;TIMESTAMP&gt;&amp;surl_token=&lt;TOKEN&gt;&amp;surl_sig=&lt;SIGNATURE&gt;", sessionToken, sessionTokenSecret, options);
                    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
                    System.out.println("\n==================================================\n\n");
                    }
                }   

                private List&lt;String&gt; listAllDocs(String recId, Rest chrome)
                        throws IndivoClientException, XPathExpressionException {
                    List&lt;String&gt; retVal = new ArrayList&lt;String&gt;();

                    Document docsDoc = (Document) chrome.records_X_documents_GET(pagingOrderingQuery, recordId, sessionToken, sessionTokenSecret, options);

                    NodeList allDocs = (NodeList) xpath.evaluate("/Documents/Document/@id", docsDoc, XPathConstants.NODESET);
                    System.out.println("allDocs.getLength(): " + allDocs.getLength());

                    for (int ii = 0; ii &lt; allDocs.getLength(); ii++) {
                        String idStr = ((Attr)allDocs.item(ii)).getValue();
                        retVal.add(idStr);
                    }
                    return retVal;
                }

                private void shareAllDocs(String recId, List&lt;String&gt; docsList, String carenetId, Rest chrome)
                        throws IndivoClientException {

                    for (int ii = 0; ii &lt; docsList.size(); ii++) {
                        String idStr = docsList.get(ii);
                        System.out.println("idStr: " + idStr);

                        System.out.println("testing -- records_X_documents_X_carenets_XPUT");
                        Document resltDoc = (Document) chrome.records_X_documents_X_carenets_XPUT(
                                recordId, idStr, carenetId, sessionToken, sessionTokenSecret, options);
                        System.out.println("sharing -- record:" + recordId + " doc:" + idStr + "   " + Utils.domToString(resltDoc) + "\n\n");
                    }



                    System.out.println("\n+===================++++++++++++++++++\n\n");
                }
            }


    }
</code></pre>
