android开发笔记
is your activity running?
这个错误一般是因为在ActivityGroup中的子窗体,换成getParent()就可以了。
Update Android SDK Tool to 22.0.0
Solution is : First Update ADT to 22.0.0 and Then Update SDK Tool to 22.0.0
ADT 22.0.0 is designed for use with SDK Tools r22. If you haven't already installed SDK Tools r22into your SDK, use the Android SDK Manager to do so
How to Update your ADT to Latest Version?
- In Eclipse go to
Help
Install New Software
--->Add
- inside
Add Repository
write the Name:ADT
(as you want) - and Location:
https://dl-ssl.google.com/android/eclipse/
- after loading some time you will get
Developer Tools
andNDK Plugins
- check both if you want to use NDK in the future or check
Developer Tool
only - click
Next
Finish
R cannot be resolved to a variable
Android开发过程中,碰到R cannot be resolved to a variable的报错信息,好像没有很确定的错误原因,一般来说,我总结出几个可能的解决方法,希望试过以后管用。。。
1. 检查Android 的SDK是否丢失需要重新下载,检查build path
2.确保class没有import Android.R;
3,错误class引用的layout的xml文件没有错误
4.检查AndroidManifest.xml文件,里边的package,layout配置文件,strings.xml等的字符串全部书写正确
5.layout的xml文件中引用的strings.xml中的字符串拼写完全正确
6.在layout 的xml文件手写添加一个控件,看id能否在R.java中自动生成,如果不能,那很大可能就是这个layout 的xml文件有问题,查看格式是否使用正确,或者包含什么非法字符串,或者调用到了不正确的字符串,等等,可以使用排除法,挨个去掉控件,直到发现error message消失或者id能在R.java中自动生成。
7.删掉gen文件夹,使R.java重新自动生成一次,如果不能生成,继续检查layout的xml文件是否有如上不易发觉的问题
8.Clean project ,重新build,或者重新import project。
9.重启eclipse
10.重启电脑,以防Android 虚拟机的问题
11.最后一招,从eclipse-->Windows-->Android SDK Manager,删除所有已下载的sdk。然后删除Eclipse ADT。重装ADT,重新下载SDK。我的问题就是这样解决的。
再不行的话,就自求多福了。
Best way to add Activity to an Android project in Eclipse?
You can use the "New Class" dialog, but that leaves other steps you need to do by hand (e.g. adding an entry to the manifest file). If you want those steps to be automated, you can create the activity via the manifest editor like this:
- Double click on AndroidManifest.xml in the package explorer.
- Click on the "Application" tab of the manifest editor
- Click on "Add.." under the "Application Nodes" heading (bottom left of the screen)
- Choose Activity from the list in the dialog that pops up (if you have the option, you want to create a new top-level element)
- Click on the "Name*" link under the "Attributes for" header (bottom right of the window) to create a class for the new activity.
When you click Finish from the new class dialog, it'll take you to your new activity class so you can start coding.
Five steps might seem a lot, but I'm just trying to be extra detailed here so that it's clear. It's pretty quick when you actually do it.
判断一个Activity是否存在于系统中
Intent intent = new Intent();
intent.setClassName("包名", "类名");
if(getPackageManager().resolveActivity(intent, 0) == null) {
//说明系统中不存在这个activity
}
/** 要注意packageName 可以同伙 getPackageName()得到,指的是apk的包路径,className 用类的全路径也就是 xx.xx.xx.类名 */
Android Spinner Error : android.view.WindowManager$BadTokenException: Unable to add window
I found a solution for badTokenExcaption
In your activity's onCreate()
method replace the line setContentView(R.layout.XXXXX)
by
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.XXXXX, null); this.setContentView(viewToLoad);
Android包名的一般命名规则
com.公司名.项目名.功能名
ActivityGroup AlertDialog的问题
new AlertDialog.Builder(xxxActivity.this)
改为:
new AlertDialog.Builder(xxxActivity.this.getParent())
Searching for a string in a String-Array item element
<?xml version="1.0" encoding="utf-8"?><resources> <string-array name="android"> <item>Android is a software stack for mobile devices that includes an operating system, middleware and key applications.</item> <item>Google Inc. purchased the initial developer of the software, Android Inc., in 2005..</item> </string-array>
String[] androidStrings = getResources().getStringArray(R.array.android); for (String s : androidStrings) { int i = s.indexOf("software"); if (i >= 0) { // found a match to "software" at offset i } }
referer: http://stackoverflow.com/questions/6501245/searching-for-a-string-in-a-string-array-item-element
关于ADB server didn't ACK的问题
编译运时时Eclipse报错:
[2012-06-19 15:22:19 - adb] ADB server didn't ACK
[2012-06-19 15:22:19 - adb] * failed to start daemon *
这个应该是5037端口被其它进程序占用了, 比如豌豆荚, 91助手等
打开cmd, 输入:
netstat -a -o 5037
接着输入:
tasklist /fi "pid eq 4792"
结束这个进程,然后重启Eclipse, OK!
The connection to adb is down, and a severe error has occured.
cmd到sdk tools文件路径下
adb kill-server
然后再:
adb kill-server
Android java.lang.NoClassDefFoundError 的解决办法
看错误是类没有找到,但是代码中确实有这个类,编译没错,执行的时候报这个异常。
我同事的机器没事,我的有问题。
想了一下差别,就是.classPath文件不一致。
后来进 project - properties-java build path - Order and Export,确认这个类打勾.
然后试着调了一下顺序,
让工程名/gen在工程名/src之上,问题居然解决了
listview之间的黑线如何去掉啊
方法1:listView.setDividerHeight(0);
方法2:this.getListView().setDivider(null);
方法3:android:divider="@null"
android:cacheColorHint="#00000000" 设置其为透明!! 默认为黑色!!!!!