Android常见的错误整理(不定时更新)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lg491733638/article/details/47664829
1 .将Bitmap影像到FrameLayout,我解码的图像转换成 Drawable ,然后将其设置为背景的 FrameLayout 
java.lang.NoSuchMethodError: android.widget.FrameLayout.setBackground() 
ByteArrayInputStream imageStream2= new ByteArrayInputStream(cardbackground); 
Bitmap Imagebackground = BitmapFactory.decodeStream(imageStream2); 
Drawable imagebakground=new BitmapDrawable(getResources(),Imagebackground); 
framelayout.setBackground(imagebakground);

解决方法:setBackground()方法,在添加 API 级别 16。使用setBackgroundDrawable()相反用setBackground
if  (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  
         framelayout.setBackground(imagebakground);
  
     else  {
  
         frameLayout.setBackgroundDrawable(imagebakground);
  
     }
2.无法使用网络:Permission denied(maybe missing internet permission)

在AndroidMainifest.xml中增加允许使用网络选项(在</application>结束标签之后>):

解决方案:<uses-permission android:name="android.permission.INTERNET" />

3. android.content.ActivityNotFoundException: Unable to find explicit activity class {xxxx}

在AndroidMainifest.xml中增加activity的申明,如:

 解决方案:<activity android:name=".xxxActivity" > </activity>

猜你喜欢

转载自blog.csdn.net/lg491733638/article/details/47664829