最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 常見bug匯總及解決方案

 更新時(shí)間:2021年03月24日 11:10:16   作者:龍旋  
這篇文章主要介紹了Android 常見bug匯總及解決方案,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下

作為開發(fā)人員,平時(shí)總會(huì)遇到各種各樣的問題,之前都沒有收集bug的習(xí)慣,遇到相同的問題總會(huì)有種莫名的熟悉感,或許把問題都匯總,方便查找,也可以給大家踩踩坑,后面會(huì)陸續(xù)更新補(bǔ)充!

1、關(guān)于使用OkHttp運(yùn)行時(shí)出現(xiàn)的錯(cuò)誤

報(bào)錯(cuò)如下:

Static interface methods are only supported starting with Android N (--min-api 24): 
okhttp3.Request okhttp3.Authenticator.lambda$static$0(okhttp3.Route, okhttp3.Response)

大概意思就是靜態(tài)接口方法只從Android N開始使用。

解決方案:

因?yàn)殪o態(tài)接口需要在Java 8 下才支持使用,所以我們要使用靜態(tài)接口,就需要在app的build.gradle文件中配置聲明,使用Java 8編譯。

所以需要加入以下代碼來聲明:

 compileOptions {

  sourceCompatibility JavaVersion.VERSION_1_8

  targetCompatibility JavaVersion.VERSION_1_8

 }

修改如下圖所示:

添加完成以后,同步一下,然后重新運(yùn)行項(xiàng)目就可以啦。

2、圖片輪播控件com.youth.banner使用Glide異步加載圖片時(shí)發(fā)生的崩潰

錯(cuò)誤信息:

java.lang.IllegalArgumentException: You cannot start a load for a destroyed activity
 at com.b.a.e.m.b(RequestManagerRetriever.java:311)
 at com.b.a.e.m.a(RequestManagerRetriever.java:130)
 at com.b.a.e.m.a(RequestManagerRetriever.java:114)
 at com.b.a.d.c(Glide.java:697)
    at com.company.h5.c.ag$b.a(MainFragment.java:1079)
 at com.company.h5.c.ag$b.displayImage(MainFragment.java:1063)
 at com.youth.banner.Banner.setImageList(Banner.java:354)
    at com.youth.banner.Banner.start(Banner.java:262)

根據(jù)錯(cuò)誤信息找到發(fā)生閃退的代碼位置:

 //自定義的圖片加載器
 private class ImgLoader extends ImageLoader {
  @Override
  public void displayImage(Context context, Object path, ImageView imageView) {  
  RoundedCorners roundedCorners = new RoundedCorners(20);
   RequestOptions options = new RequestOptions().bitmapTransform(roundedCorners);
   //報(bào)錯(cuò)地方
   Glide.with(context).load((String) path).apply(options).into(imageView);
  }
    }

跟蹤日志進(jìn)入Glide調(diào)用的地方發(fā)現(xiàn),出現(xiàn)在

RequestManagerRetriever.assertNotDestroyed()

方法中:

 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
 private static void assertNotDestroyed(Activity activity) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed()) {
   throw new IllegalArgumentException("You cannot start a load for a destroyed activity");
  }
    }

這個(gè)錯(cuò)誤是使用Glide異步加載圖片的時(shí)候,Activity已經(jīng)Destroyed

解決方案:

1、在使用Glide加載圖片前,先進(jìn)行Activity是否Destroy的判斷:

 /**
  * 判斷Activity是否Destroy
  * @param activity
  * @return
  */
 public static boolean isDestroy(Activity mActivity) {
  if (mActivity== null || mActivity.isFinishing() || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())) {
   return true;
  } else {
   return false;
  }
    }

2、在錯(cuò)誤的位置進(jìn)行替換:

 //自定義的圖片加載器
 private class ImgLoader extends ImageLoader {
  @Override
  public void displayImage(Context context, Object path, ImageView imageView) { 
   //添加判斷 
   if(!isDestroy((Activity)context)){
    RoundedCorners roundedCorners = new RoundedCorners(20);
    RequestOptions options = new RequestOptions().bitmapTransform(roundedCorners);
    Glide.with(context).load((String) path).apply(options).into(imageView);
   }
  }
    }

這樣就解決啦。

3、接入容聯(lián)七陌客服系統(tǒng),進(jìn)入客服界面時(shí)閃退問題

錯(cuò)誤信息:

圖片看起來不清晰,看報(bào)錯(cuò)代碼:

java.lang.NoSuchMethodError: No virtual method into (Landroid/widget/ImageView;)Lcom/bumptech/glide/request/target/Target; in class Lcom/a/a/i; or its super classes (declaration of 'com.a.a.i' appears in/data/app/com.sami91sami.h5-1/base.apk)

我們可以根據(jù)報(bào)錯(cuò),跳到報(bào)錯(cuò)的地方:

該報(bào)錯(cuò)的意思就是:沒有 

into(Landroid/widget/ImageView)

的方法,代碼能編譯通過,說明項(xiàng)目中肯定是添加依賴了,那怎么還會(huì)報(bào)這個(gè)錯(cuò)誤呢?還沒添加依賴之前,項(xiàng)目中也是使用的Glide進(jìn)行圖片的加載,會(huì)不會(huì)是項(xiàng)目中的Glide與容聯(lián)Demo中的Glide有沖突呢。

我們可以根據(jù)報(bào)錯(cuò)的地方into方法,點(diǎn)進(jìn)入看源碼:

可以看到容聯(lián)Demo使用的Glide版本是3.7.0。

再來看看項(xiàng)目中Glide使用的版本:

可以看到項(xiàng)目中使用的Glide版本是4.5.0。

這時(shí)就想到真的很大概率是兩者的Glide版本有沖突了。

果然將容聯(lián)Demo中的Glide版本改成4.5.0之后,編譯運(yùn)行進(jìn)入客服界面后,沒有報(bào)錯(cuò)了,完美解決。

4、android 7.0系統(tǒng)解決拍照的問題

報(bào)錯(cuò)信息:

# main(1)
android.os.FileUriExposedException
file:///storage/emulated/0/xiangmu/3462884.jpg exposed beyond app through ClipData.Item.getUri()

android.os.StrictMode.onFileUriExposed(StrictMode.java:1816)
android.net.Uri.checkFileUriExposed(Uri.java:2350)

解決方法如下:

1.在相對應(yīng)的頁面中,寫如下的方法:

private void initPhotoError(){
  // android 7.0系統(tǒng)解決拍照的問題
  StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
  StrictMode.setVmPolicy(builder.build());
  builder.detectFileUriExposure();
    }

2.在onCreate中調(diào)用上述的方法。

5、使用RecyclerView滑動(dòng)閃退問題

錯(cuò)誤信息:

圖片看起來不清晰,看報(bào)錯(cuò)代碼:

IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter

看這個(gè)代碼,只是并沒有報(bào)到我們自己的代碼里面來,在底層就崩潰了,在app層面并沒有,彈出一個(gè)框,說應(yīng)用程序已奔潰,而是直接就沒了,用戶感覺很奇怪。這種異常并不是很容易出現(xiàn),而是偶爾出現(xiàn),我的也是在后臺奔潰日志中,發(fā)現(xiàn)了這種異常,我們自己都不知道什么地方報(bào)錯(cuò)的。

解決方案如下:

1、創(chuàng)建一個(gè)類LinearLayoutManagerWrapper

繼承LinearLayoutManager,重寫onLayoutChildren方法

public class WrapContentLinearLayoutManager extends LinearLayoutManager {
 public WrapContentLinearLayoutManager(Context context) {
  super(context); 
 } 

 public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { 
  super(context, orientation, reverseLayout); 
 } 

 public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
  super(context, attrs, defStyleAttr, defStyleRes); 
 } 

 @Override 
 public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
  try { 
   super.onLayoutChildren(recycler, state); 
  } catch (IndexOutOfBoundsException e) { 
   e.printStackTrace(); 
  } 
 } 
} 

2、設(shè)置RecyclerView的布局管理為

WrapContentLinearLayoutManager對象

mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

其實(shí)這也不是什么解決方案,只是把這個(gè)異常捕獲了,不讓他奔潰了,這個(gè)問題的終極解決方案還是得讓google去修復(fù)。

以上就是Android 常見bug匯總及解決方案的詳細(xì)內(nèi)容,更多關(guān)于Android 常見BUG及解決的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

山阴县| 本溪市| 咸阳市| 双流县| 马龙县| 新野县| 方山县| 赞皇县| 石屏县| 乾安县| 芒康县| 买车| 垫江县| 临漳县| 嘉善县| 自贡市| 昆山市| 青田县| 姚安县| 屯昌县| 麻栗坡县| 运城市| 怀来县| 大厂| 昌图县| 突泉县| 若羌县| 团风县| 菏泽市| 五家渠市| 文安县| 阳山县| 芜湖县| 华阴市| 雷州市| 双柏县| 凤庆县| 鲁甸县| 安塞县| 连城县| 乾安县|