1. Unable to use the network: Permission denied (maybe missing internet Permission)
A: Increase the Allow network option in Androidmainifest.xml (after closing the tag >):
Java code:
- Uses-permission android:name= "Android.permission.INTERNET"/>
Copy Code
2. Activity class not found: Android.content.ActivityNotFoundException:Unable to find explicit activity class {XXXX}. Add a statement of activity in the androidmainifest.xml, such as:
Java code:
- < activity Android:name = ". Xxxactivity" >
- </activity >
Copy Code
3. Why can't I find the Startsubactivity method?
A: Now, please use the Startactivityforresult method instead of the old Startsubactivity method.
4, unable to load the XML view, reported Java.lang.NullPointerException exception. Forgot to load the activity's layout file:
Java code:
- Setcontentview (R.layout.main);
Copy Code
5, unparsed aapt error (s)! Check the console for output
A: But when you can't find an error on your console or you can't read the error, click Project ——— >clean. It will be fine.
6. The difference between Requestcode and ResultCode
When usingStartactivityforresult ()AndOnactivityresult ()will be used separately when theRequestcodeAndResultCode, it is sometimes very easy to confuse 2 parameters.RequestcodeAndResultCodeConfusion explains the wrong.Startactivityforresult (Intent Intent, Int requestcode). Intentto B, do not explain, do not understand you still play mobile phone forget, don't think about the development of thingsRequestcode >=0Well, whatever it is, use it inOnactivityresult ()Distinguish which sub-module data is returned, if there is C.java, D or even e sub-modules, each area is separated by differentRequestcodeJust fine.setresut (int resultcode, Intent Intent). ResultCodeIf the B sub-module may have several different results returned, it can be distinguished by this parameter. There is also a special RESULT_OK value, there is no special case to use it, the SDK is described. Intent continue not to explain, passed back to A'sOnactivityresult (). Onactivityresult (int requestcode, int resultcode, Intent Intent)
Here are three not to explain, and the above corresponding to the thing. If notRequestcodeAndResultCodeDistinguish it, as long as there are otherActivity Setresultto theA Onactivityresult ()will be treated without discrimination.
7. Unable to download files toSDAdvant inManifestThe file adds:
Java code:
- < uses-permission Android:name = "Android.permission.WRITE_EXTERNAL_STORAGE"/>
Copy Code
8. Let the control center in the parent container:
Java code:
- Android:layout_gravity= "Center_vertical"
Copy Code
9. Align the controls at both ends:
The following code gives way to the left and right alignment of the two controls on the same line individually:
Java code:
- < 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>
Copy Code
10, global variables application Context
Create a subclass of your own android.app.Application , and then declare this class in manifest, which is what Android does to create a globally available instance that you can use anywhere else The Context.getapplicationcontext () method gets the instance, which gets the state (variable) in it. Here's a look at the demo:
java code:
- 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 ();
- }
- }
Copy Code
This effect is the same as using static variables, but it is more in line with the Android architecture. Using this method, you need to configure it in androidmanifest.xml :
Java code:
- <application
- Android:name= ". MyApp "
- android:icon= "@drawable/icon"
- Android:label= "@string/app_name" >
Copy Code
Common Android Errors and tricks