2012年11月25日 星期日

Andriod Permission: Connect to Internet



The following permission should be grant for the internet connection from Android Application.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... />
    ...
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

[RESOLVED] E/ERR(1183): org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused

Today I am trying to write an android program to retrieve an XML data from localhost server. When running the program, the following error occurs:

E/ERR(1183): org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused




              String url = "http://localhost:100/test.xml";

              try {
                     DefaultHttpClient httpClient = new DefaultHttpClient();
                     HttpPost httpPost = new HttpPost(url);

                     HttpResponse httpResponse = httpClient.execute(httpPost);
              } catch (ClientProtocolException e1) {
                     // TODO Auto-generated catch block
                     e1.printStackTrace();
              } catch (IOException e1) {
                     // TODO Auto-generated catch block
                     e1.printStackTrace();
              }
             
 


Solution:
The Android emulator could not recognize the localhost and results in connection refused.
To resolve, we can change the localhost to the ip address 10.0.2.2 and try again, problem resolved.

e.g. String url = "http://10.0.2.2:100/test.xml";
 



2012年11月15日 星期四

The project was not built due to "Could not delete '/XXXX'."

Sometimes when building the java application, the following error occurs:

The project was not built due to "Could not delete '/XXXX'.". Fix the problem, then try refreshing this project and building it since it may be inconsistent



Solution:
1. Click: Project --> Clean
 


2. After rebuild, the error is gone!

2012年11月11日 星期日

[RESOLVED] INSTALL_FAILED_MISSING_SHARED_LIBRARY when using Google API

Today I'm trying to write Google Maps Application on Android. When running the application, the following errors occur:



[2012-11-11 20:20:45 - XXX] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
[2012-11-11 20:20:45 - XXX] Please check logcat output for more details.
[2012-11-11 20:20:45 - XXX] Launch canceled!


Resolution:
It is because Google Maps is not installed on the device / emulator.

1. Choose the Android Version and install "Google APIs by Google Inc."

2. In project properties, choose Google APIs as the Project Build Target.

3. Build again and success!


2012年11月4日 星期日

Unable to resolve target 'android-14'

When importing an old source code in eclipse today, the following error occurs:
Unable to resolve target 'android-14'


It is because android-14 does not installed in the machine.
You can change the android version via the project properties. For example, the API version for Android 4.0.3 is 15.


Then open the AndroidManifest.xml to change the sdk version to 15.
<uses-sdk android:minSdkVersion="15" />