Android开发常见错误及技巧
来源:互联网 发布:seo综合站长工具 编辑:程序博客网 时间:2024/05/29 06:38
1、无法使用网络 :Permission denied(maybe missing internet permission) 在AndroidMainifest.xml中增加允许使用网络选项(在</application>结束标签之后>): <uses-permission android:name="android.permission.INTERNET" /> 2、找不到activity类: android.content.ActivityNotFoundException: Unable to find explicit activity class {xxxx} 在AndroidMainifest.xml中增加activity的申明,如: < activity android:name = ".xxxActivity" > </ activity > 3、为什么我找不到 startSubActivity 方法? 现在,请使用 startActivityForResult 方法来代替旧的startSubActivity方法。 4、无法加载xml中的view,报 java.lang.NullPointerException 异常 忘记加载activity的layout文件: setContentView(R.layout.main); 5、Unparsed aapt error(s)! Check the console for output 但是你的控制台上找不到错误或者 看不懂错误的时候,点 Project--------->clean ..就会没问题 6、requestCode和resultCode的区别 在使用startActivityForResult()和onActivityResult()时,会分别用到requestCode和resultCode,有时候极容易将2个参数混淆起来。 7、无法下载文件到SD卡中 在manifest文件中加上:< uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" /> 8、让控件在父容器中居中: android:layout_gravity= "center_vertical" 9、控件两端对齐: 如下代码让 位于同一行的两个控件分别左对齐和右对齐: < 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软键盘 把控件 往上挤的解决办法: 键盘区域外才是屏幕的边缘,定义布局文件时使用:android:gravity="bottom"的话就会被挤到上部! 解决办法: 在此工程的androidMainfest.xml文件中对应的Activity中写入 android:windowSoftInputMode="adjustPan" 或者在配置文件中把布局文件的大小写死! 11、在布局中使用scrollview: 把原来的布局用<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 12、全局变量Application Context 创建一个属于你自己的android.app.Application的子类,然后在manifest中申明一下这个类,这是android就为此建立一个全局可用的实例,你可以在其他任何地方使用Context.getApplicationContext()方法获取这个实例,进而获取其中的状态(变量)。 下面看一下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(); ... } } 这个效果就是使用静态变量是一样的,但是其更符合android的架构体系。 使用这种方法的话需要在 AndroidManifest.xml中配置一下: <application android:name=".MyApp" android:icon="@drawable/icon" android:label="@string/app_name"> 链接:http://blog.csdn.net/kmyhy/archive/2010/09/21/5899536.aspx
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none"></ScrollView>括起来即可实现视图的滚动。
- Android开发常见错误及技巧
- Android开发常见错误及技巧
- 谷歌Android开发常见错误及技巧
- 谷歌Android开发常见错误及技巧
- Android开发常见错误及技巧
- Android开发常见错误及技巧
- Android开发常见错误及调试技巧
- 从网上查到的Android开发常见错误及技巧
- Git在开发android系统时常用的技巧及常见错误解决方案
- Android 开发常见错误 及 解决办法
- Android 开发常见错误及解决方法集锦
- Eclipse开发Android常见错误及解决办法
- Android开发中常见错误与开发小技巧
- android开发之常见的android开发错误及解决方案
- Android开发-----NDK开发中的一些常见错误及解决办法
- Android开发-----NDK开发中的一些常见错误及解决办法
- Android开发-----NDK开发中的一些常见错误及解决办法
- Android 常见错误和技巧
- repository的选择
- 其实山寨也不容易
- 拿什么拯救你,我的路由器
- SCJP认证范围 1.4 声明接口
- IPhone游戏开发纵谈
- Android开发常见错误及技巧
- SNIA 共享存储模型
- Java语言中链表和双向链表的实现
- 2003配置 armv5问题
- 十年莽撞IT路(冯大辉发展历程)
- VC读写INI文件(转)
- 新手不要炒股
- Cinterion(原西门子)于2011年2月14日情人节发布全球最小的GPRS模块---BGS2
- MySQL数据库中的Show命令具体用法 转自:http://www.chinaz.com/Program/Mysql/052I00342008.html