Common Errors and skills in Android development and common errors in android Development

Source: Internet
Author: User

Common Errors and skills in Android development and common errors in android Development

1. Network unavailable: Permission denied (maybe missing internet permission)

Add the allowed Network option in AndroidMainifest. xml (after the </application> end tag> ):

<Uses-permission Android: name = "android. permission. INTERNET"/>

 

2. activity class not found: android. content. ActivityNotFoundException: Unable to find explicit activity class {xxxx}

Add the activity Statement in AndroidMainifest. xml, for example:

 

<Activity android: name = ". xxxActivity">

</Activity>

 

3. Why can't I find the startSubActivity method?

Now, use the startActivityForResult method to replace the old startSubActivity method.

 

4. view in xml cannot be loaded, and a java. lang. NullPointerException exception is reported.

Forget to load the layout file of the activity:

SetContentView (R. layout. main );

 

5. Unparsed aapt error (s )! Check the console for output

However, when an error cannot be found on the console or you cannot understand the error,Click Project ---------> clean... No problem.

Http://hovertree.com/menu/android/

6. Differences between requestCode and resultCode

When startActivityForResult () and onActivityResult () are used, requestCode and resultCode are used respectively. Sometimes, it is very easy to confuse the two parameters.

 

The obfuscation between requestCode and resultCode is incorrect. StartActivityForResult (Intent intent, Int requestCode)Intent passed to B. It doesn't explain. If you don't understand it, you can still play with your phone. Don't worry about development. requestCode> = 0 is good. It can be used in onActivityResult () which sub-module is used to return data? If C. for java, D, and even E sub-modules, it is better to separate different requestcodes for each partition. SetResut (int resultCode, Intent intent)ResultCode if the submodule B may return several different results, you can use this parameter to identify and distinguish. There is also a special RESULT_ OK value here, it is good to use it without special circumstances, the sdk has instructions, ah. Intent continues without explanation. onActivityResult () returned to () OnActivityResult (int requestCode, int resultCode, Intent intent)There is no need to explain the above three items. If you do not distinguish requestCode from resultCode, there will be no difference as long as other activities setResult reach A onActivityResult.

 

 

7. Files cannot be downloaded to the SD card.

Add <uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/> to the manifest file.

 

8. Center the control in the parent container:

 

Android: layout_gravity = "center_vertical"

 

9. Align the two ends of the control:

Run the following code to align the two controls in the same row to the left and right respectively:

 

<RelativeLayout

Xmlns: Android = "http://schemas.android.com/apk/res/android"

Android: background = "@ drawable/top"

Android: layout_width = "fill_parent"

Android: layout_height = "wrap_content"

> <ImageView

Android: id = "@ + file_browser/imgRefresh"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: layout_marginLeft = "10px"

Android: src = "@ drawable/refresh"

Android: layout_centerVertical = "true"

>

</ImageView>

<ImageView

Android: id = "@ + file_browser/imgCheck"

Android: layout_alignParentRight = "true"

Android: layout_width = "wrap_content"

Android: layout_height = "wrap_content"

Android: layout_marginRight = "10px"

Android: src = "@ drawable/close"

Android: layout_centerVertical = "true"

>

</ImageView>

</RelativeLayout>

 

10,Android keypadSetWidgetSolution to the push:

Outside the keyboard area is the edge of the screen. when defining the layout file, android: gravity = "bottom" will be squeezed to the top!

Solution:

Write android: windowSoftInputMode = "adjustPan" to the Activity corresponding to the androidMainfest. xml file of this project"

Or the layout file is case-insensitive in the configuration file!

11. Use scrollview in the layout:

The original layout with <ScrollView xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: scrollbars = "none"> </ScrollView> to scroll the view.

 

12. global variable Application Context

 

Create your own android. app. subclass of Application, and then declare this class in manifest. This is why android creates a global available instance for this purpose. You can use Context anywhere else. the getApplicationContext () method obtains the instance and the status (variable ). Let's take a look at the Demo:

Class MyApp extends Application {

Private String myState;

Public String getState (){

Return myState;

}

Public void setState (String s ){

MyState = s;

}

}

Class Blah extends Activity {

@ Override

Public void onCreate (Bundle B ){

...

MyApp appState = (MyApp) getApplicationContext ());

String state = appState. getState ();

...

}

}

The effect is that static variables are the same, but they are more in line with the android architecture. To use this method, configure it in AndroidManifest. xml:

<Application android: name = ". MyApp"

Android: icon = "@ drawable/icon"

Android: label = "@ string/app_name">

 

13,Android simulators send text messages by phone

The GPhone simulator has a unique number: 15555218135, which is similar to the SIM card number of our mobile phone. To implement dialing, use a mobile phone? Of course not!

Simpler, three steps:

1. Open the terminal

2. Connection: telnet localhost 5554 (5554 is the number shown above after you open the simulator)

3. Command: gsm call 15555218135

Look! Is a call displayed on the simulator? The same as the physical phone.

Text messages are as simple as text messages. Repeat steps 1 and 2 and modify the third part of the command:

Sms send 15555218135 Hello, this is a Message.

 

14. ListView cannot trigger the OnItemClickListener listener

Check whether EditText is used in the row layout file bound to the row. If so, set the focusable attribute of EditText to false.

Recommended: http://www.cnblogs.com/roucheng/p/sdka.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.