2015-10-27 124 views
1

Im與Butterknife合作,我有一個問題,當我想改變另一個片段時,應用程序失敗。這是我的第一個片段Butterknife和碎片

@Bind(R.id.tilNombre) TextInputLayout tilNombres; 
@Bind(R.id.tilApellido) TextInputLayout tilApellido; 
@Bind(R.id.tilDocumento) TextInputLayout tilDocumento ; 
@Bind(R.id.btnContinuar) Button btnContinuar; 
public RegistroFragment() { 
    // Required empty public constructor 
} 


@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    View view = inflater.inflate(R.layout.fragment_registro, container, false); 
    ButterKnife.bind(this, view); 
    return view; 
} 

@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
    app(); 
} 

void app(){ 
    tilNombres.setHint(getResources().getString(R.string.nombres)); 
    tilApellido.setHint(getResources().getString(R.string.apellidos)); 
    tilDocumento.setHint(getResources().getString(R.string.licencia)); 

    events(); 
} 

void events(){ 

    btnContinuar.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      RegistroTwoFragment registroTwoFragment = new RegistroTwoFragment(); 
      android.support.v4.app.FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); 
      fragmentTransaction.replace(R.id.contenedorRegistro, registroTwoFragment).commit(); 
     } 
    }); 
} 

在該代碼中我沒有任何問題,問題是在接下來的部分

public class RegistroTwoFragment extends Fragment { 

@Bind(R.id.tilCorreo) TextInputLayout tilCorreo; 
@Bind(R.id.tilClave) TextInputLayout tilClave; 
@Bind(R.id.btnRegistrar) TextInputLayout btnRegistrar; 
@Bind(R.id.tviRetroceder) TextInputLayout tviRetroceder; 

public RegistroTwoFragment() { 
    // Required empty public constructor 
} 


@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    View view = inflater.inflate(R.layout.fragment_registro_two, container, false); 
    ButterKnife.bind(this,view); 
    return view; 
} 

@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
    app(); 
} 

void app(){ 
    tilCorreo.setHint(getResources().getString(R.string.correo)); 
    tilClave.setHint(getResources().getString(R.string.contrasena)); 

    events(); 
} 

void events(){ 
    tviRetroceder.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      RegistroFragment registroFragment = new RegistroFragment(); 
      android.support.v4.app.FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction(); 
      fragmentTransaction.replace(R.id.contenedorRegistro, registroFragment).commit(); 
     } 
    }); 
} 

的logcat的說:無法綁定意見的com.example.aato。 ciudadano.fragments.RegistroTwoFragment;有誰知道這個問題?

回答

0

有些事情要檢查:

  1. 確保fragment_registro_two佈局實際上包含在你的@Bind(R.id.xyz)語句使用的資源ID。
  2. 確保對每個綁定到每個資源的變量使用正確的類型。在你的情況下,你確定TextInputLayout實際上是所有綁定資源的正確類型嗎?