Android Common error handling (ii)

Source: Internet
Author: User

Exam month is very busy, finally after the test can continue to write code learning ... Also hope that the small partners more advice ha ~


First,Java.lang.OutOfMemoryError

    1. For Java, the heap used to display pictures on a virtual machine is only 64MB, and in Android each application is about 16MB of memory (refer to Training/displaying-bitmaps). In other words, once we use a class like bitmap to load a picture, it is very likely that the 64MB heap will be fully occupied. In addition, if the object still has a reference, the object will still exist in the heap, and the Java garbage collection mechanism will not process them. In this case, you need to use some tools to evaluate how much space (static) the image you have to use for your project, and then to modify the heap size so that it can accommodate the picture you need.
    2. Do not use a method similar to recycle (), as 1 says, such a method does not change such an error (the reference is still in)
    3. There may be a dead loop in the code, creating object entities repeatedly
    4. Take advantage of low-pixel photos when using low-pixel images, and avoid giving preference to loading high-resolution images (high-pixel images occupy significantly more memory than low-pixel images)

Second, the picture can not be filled ImageView

This solution is actually quite simple, using ImageView's Setscaletype () method, parameter selection Fitxy. If you think this will distort the picture, just use the Centercrop parameter


Third, Runtimeerror:you cannot combine custom titles with other title features

The mistake is to say that you can't mix multiple heading styles, there are several workarounds:

  1. All of the heading style settings on the androidmanifest with Android:theme= "" settings, as for the title of the style of their own XML implementation of the Good Bai
  2. Join in the Styles.xml.<Item name="Android:windowactionbar">false</Item>, because there are a lot of custom title bar in the tutorial, there will be a set theme statement is used Windowactionbar, by changing this to false can avoid such a conflict
  3. In the activity has already set the title of the theme, the result of the tab inside set up another theme (such as Viewpager)
  4. When multiple packages are imported into the project, it is possible that the settings for theme are different in the androidmanifest between packages, which can also cause this error

Iv. Jar mismatch! Fix your depedenciesThe majority of this error occurs when multiple packages are imported in a project, mainly because the jar used by different packages may not be the same. Take me for example:
I was using the Library1, Library2 and the project itself Android-support-v4.jar, there was this error, said I have 3 bags, I do not recognize which one to use. The solution is to unify the jar of the three packages, so there's a way to do it online:
Replace the jar of the library with the jar of the project, and then it's all right. But I think another way to see it on the StackOverflow is better:
start by using the Add support Library in Android tools for your project, then remove all the Android-support-v4.jar, and each project or Library is in the build Path menu ADD external jar or in Project Properties->android->library->add ... Add the jar, so that the package can be unified
Wu, ClassNotFoundException
This error may be because the package is not fully imported, possibly because the name of the class to start is not written on Androidmanifest

Android Common error handling (ii)

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.