您的位置:首页 > 移动开发 > Android开发

Android开发常见问题及解决方法小结

2012-11-30 09:31 691 查看

Android开发常见问题及解决方法小结

1.ActivityManager: Warning: Activity not started, its current taskhas been brought to the front
说明:模拟器中已经有一个实例在运行。
解决方法:退出模拟器中运行的程序,再次运行即可解决!

2.Nogrammar constraints (DTD or XML schema) detected for the document
说明:在编辑器中看到像这样关于缺少语法约束(DTD
或 XML
架构)的警告,尽管忽略这些警告。
解决方法:windows ->preferences -> xml -> xml files -> validation -> Indicate when nogrammar is specified:
选择Ignore即可。

3. R.java:no such file or directory
说明:R类不存在。
解决方法:Windows->Preference->Java->BuildPath中,将Folders改为选中Projects即可。

4.res\layout\*.xml:Invalid file name: must contain only [a-z0-9_.]
说明:样式XML的文件名起的不符合要求。文件名中只能是小写英文字符、数字、"_"或者"."。

5.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES
说明:这样的问题主要是签名冲突造成的,比如你使用了ADB的debug权限签名,但后来使用标准sign签名后再安装同一个文件会出现这样的错误提示。
解决方法:卸载原有版本再进行安装,而adb install-r参数是无法解决这个问题。

6.Android程序为什么没有退出设计?
答:Google Android平台在设计程序声明周期上比较特殊,可能是考虑到第二次加载时保证速度的原因而没有强制加入内存释放问题,所有的资源回收由Dalvik
GC自动完成,所以在设计开发时一定要注意Activity和 Service类的生命周期问题,显示在最上层的窗口将有最高的优先级,当Android操作系统内存不够用时自动将会根据历史栈按优先级强制杀掉进程。

7.EmulatorControl GPS轨迹发送按钮有时会变灰不可点。
答:重启Eclipse。

8.android.content.ActivityNotFoundException:Unable to find explicit activity class {XXX}
答:在AndroidMainifest.xml中声明一下XXXActivity,如:<activity
android:name = “.XXXActivity” >

9.模拟器打不开,提示项目有错误(Your project contains error(s)...)
答:也许项目里没有错误,但仍会出现这种提示,刷新重启仍然解决不了的话,就删除项目(不用选择把文件删除),重新导入一下。

 

10.Eclipse报错"No embedded stylesheetinstruction for file"的解决方法

 

21:11:57,015 INFO [main] Main -javax.xml.transform.TransformerFactory=null

21:11:57,015 INFO [main] Main - java.endorsed.dirs=D:\ProgramFiles\Java\jre6\lib\endorsed

21:11:57,031 INFO [main] Main - launchFile:E:\JavaWebAPP\.metadata\.plugins\org.eclipse.wst.xsl.jaxp.launching\launch\launch.xml

21:11:58,453 FATAL [main] Main - No embedded stylesheet instruction for file:file:/E:/JavaWebAPP/myApp/config.xml

org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException: No embeddedstylesheet instruction for file: file:/E:/JavaWebAPP/myApp/config.xml

at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:225)

atorg.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:186)

at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.Main.main(Main.java:73) Causedby: org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException: No embeddedstylesheet instruction for file: file:/E:/JavaWebAPP/myApp/config.xml

at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:214)

... 2 more

 

分析:因为编辑界面显示的是一个xml文件,所以点Run按钮时,Eclipse并不是去Project中寻找main()方法来运行,而是“运行”当前的xml文件,至于是在干什么我也不清楚,结果也很简单,因为你的xml不符合Eclipse的“运行”要求,所以它自然要报错了。

eclipseseems to want to "run" whatever you have selected. go knows what it'sdoing when you try to run something like strings.xml, but it fails andgenerates a .out file ... which then corrupts your android project becauseandroid
doesn't understand all the .out files laying all of the place.

 

解决方法:运行Project时不要把编辑界面放在xml上,或者,手动选择main()方法所在的类,点"Run"。

removeall of the *.out.* files in your project. when you run, click on

the project (top level) in the package browser (left pane) first, and

ensure that you are doing "run as" an android application.

 

11.出现An internal error occurredduring: "Launching New_configuration". Path for project must haveonly one segment.提示错误。

在Eclipse中按照如下操作

Project -> Properties ->Run/Debug Settings:

1. select "Launching New_configuration"

2. Delete

3. OK

 

12.在DOS
下输入 android list targets
会出现android
不是内部或外部命令

找到设置环境变量的地方,然后在 path 中加入

;C:\Android\android-sdk\tools;C:\Android\android-sdk\platform-tools

 

13.Error parsing XML: unboundprefix.

< TextView

android:layout_width="wrap_content"

andriod:layout_height="wrap_content"

android:text="@string/main_title"

android:layout_gravity="center"

android:layout_marginBottom="25dip"

android:textSize="24.5sp"

/>

The reason is the word "andriod" in the 3rd lineis wrong, it should be "android".

At first I was crazy because I could not find out thereason. I should be more carefull !

 

14.AndroidFailed to install on device ‘emulator-5554′: timeout
问题的解决方法

eclipse -> window -> Preferences -> Android-> DDMS -> ADB connection time out(ms).把这个时间设置的长一些,默认是5秒,我改成20秒就ok了。然后重启模拟器,这样就不用每次重启模拟器了~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: