1. 程式人生 > >專案中遇到的 問題及解決方案

專案中遇到的 問題及解決方案

1.Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA

解決方案:1).android裝置網路連線沒開啟,例如3G網路和WIFI網路

     所以,如果遇到這種錯誤時,請先檢視網路是否已正常連線.

2).Manifest檔案沒有標明網路訪問許可權

     如果確認網路已經正常連線並且還是出這種錯誤的話,那麼請看下你的Manifest檔案是否標明應用需要網路訪問許可權,如果沒標明的話,也訪問不了網路,也會造成這種情況的.

     <uses-permission android:name="android.permission.INTERNET" />

2.專案中使用到了 Toolbar

當你需要新增選單時,就不需要使用

setSupportActionBar(mToolbar);//否則選單不可見
public void initTitleBar() {
        title.setText("登入");
mToolbar.setTitle("");
//        setSupportActionBar(mToolbar);
mToolbar.setOnMenuItemClickListener(menuItemClickListener);
mToolbar.inflateMenu(R.menu.menu_main);
}

    private 
Toolbar.OnMenuItemClickListener menuItemClickListener = new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.forget_password: startActivity(new
Intent(LoginActivity.this, FindPassWordActivity.class)); break; } return true; } };

3.在專案中使用DialogFragment 
 1).需要用圓角的dialog :首先使用了shape有了圓角 但是外層佈局還是帶方的,需要在 自定義的dialogfragment裡面 使用:getDialog().getWindow().setBackgroundDrawable(new BitmapDrawable());
 2).去掉標題:
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
 3).設定Dailog的顯示位置:
@Override
public void onStart() {
    super.onStart();
getDialog().setCanceledOnTouchOutside(true);
Window window = getDialog().getWindow();
window.setBackgroundDrawable(new BitmapDrawable());
WindowManager.LayoutParams width = window.getAttributes();
width.gravity = Gravity.CENTER;
window.setAttributes(width);
}
4:FormUrlEncoded can only be specified on HTTP methods with request body (e.g., @POST).
使用retrofit時,當時Get請求時:不可以有@FormUrlEncoded註解;當是Post請求時:至少要有一個@Field
5:LinearLayout有個屬性:divider  showDividers 可以實現分界線;
6:在使用RecyclerView的時候,onBindViewHolder方法中的position 在對資料操作的時候返回的並不是實時的:
根據SDK中的解釋,在Recyclerview 進行新增、移除item等操作時,position位置可能會變化,而所有的adapter的重新整理並不總是及時的,只有這個方法返回的才是當前item經過一些變換後所處的真正位置。
所以我們使用holder.getLayoutPosition()來獲得當前的位置;