Android problem summary

original
2014/05/01 20:32
Reading number 343

one Only the original thread that created a view hierarchy can touch its views
When initializing the activity, you need to download the image, so you restart a thread to download the image and update the UI. At this time, the above error occurs.
Reason: That is, the UI cannot be updated in a non main thread
Solution: The enabled thread downloads the image, and a new handler is used to update the UI

 

 picHandler = new Handler(); /** *Update picture thread *  * @author Administrator *  */ class UpdatePic implements Runnable { @Override public void run() { imageView.setImageBitmap(bitMap); } } /** *Download image thread *  * @author Administrator *  */ class DownloadImage implements Runnable { @Override public void run() { bitMap = PicUtil.getBitmap(tm.getSimSerialNumber()); picHandler.post(updatePic); } }

 

two java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
Activity cannot be instantiated in the following three cases:
1. The activity is not registered in the Manifest.xml list, or after the activity is created, the package name or activity class name is modified, but the configuration list is not modified, so it cannot be instantiated.
2. You have created a new package and still use the default package when registering. For example, the default package is com.ghg Dao package, you have created a new com.ghg DaoImpl package, and write a FirstActivity in this package. Note in the manifest.xml
When you write<activity android: name=". FirstActivity"/>, it means that your class is registered in the default package, and the system cannot find it in the default package, because your FirstActivity is in com.ghg DaoImpl Package
So you should write the package name and class name when registering, such as:<activity android: name="com. ghg. DaoImpl. FirstActivity"; In this way, the system can find the corresponding class in the specified package.
3. Another is that your FirstActivity is defined as an abstract class. It seems that ordinary people do not commit this situation.
If the above three cases are taken into consideration, this exception will be thrown. Check whether the constructor and oncreate() of this class exist in the activity class at the same time. If so, delete the constructor and try to initialize it in
Oncreate().
 

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
ten Collection
zero fabulous
 Back to top
Top