我有问题从我的片段roboguice中膨胀视图,并且不知道为什么会发生这种情况..
这是我的代码
头等舱
public class AppController extends RoboFragmentActivity {
@InjectView(R.id.rtlPrincipalPaginaPrincipal) RelativeLayout rtlPrincipal;
@InjectView(R.id.rtlPrincipalMenuQr) RelativeLayout rtlMenuQr;
@InjectView(R.id.rtlPrincipalPaginaTrasera) RelativeLayout rtlTraera;
private FragmentManager fragment_manager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
objFragmenManager = AppController.this.getSupportFragmentManager();
setContentView(R.layout.activitylayout);
objAnimationbjar = AnimationUtils.loadAnimation(this, R.anim.linear);
objAnimationSubir = AnimationUtils.loadAnimation(this, R.anim.linear2);
final SharedPreferences prefs =
AppController.this.getSharedPreferences("MisPreferencias",Context.MODE_PRIVATE);
LlenarHandler();//para podr recibir llamadas de las otras clases
LlenarPaginaPrincipal();// pagina principal donde mostramos las poromociones
}
private void LlenarPaginaPrincipal(){
objNavegar = new Cnavegar();
Cnavegar objNavegar= new Cnavegar();
Fragment frmTopmen = new AfrmProciones();
objNavegar.RemplazarFragmento(R.id.rtlPrincipalPaginaTrasera,frmTopmen, "AfrmProciones",objFragmenManager);
}
现在是片段
public class AfrmProciones extends RoboFragment{
@InjectView(R.id.btnCity) Button btnBajar;
@InjectView(R.id.vfShow) ViewFlipper vfPromociones;
@InjectView(R.id.prgProgresoPomos) ProgressBar pgrProgreso;
@InjectView(R.id.Crono) Chronometer objCrono;
View vPromos;
private Handler mHandler;
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
ArrayList<Cpromocion> lstPromo;
@SuppressWarnings("deprecation")
private final GestureDetector detector = new GestureDetector(new MyGestureDetector());
AccesoBd objAcceso;
Promociones taspromociones;
ObjectAnimator objAnimFondo;
AlarmManager objAlarma;
BroadcastReceiver objBroadcast;
int itiempo;
public AfrmProciones(Handler rHandler){
mHandler = rHandler;
}
public AfrmProciones(){
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
RoboGuice.getInjector(getActivity()).injectMembers(this);
RegistrarEventos();
LlenarPromociones();
return vPromos;
}
private void RegistrarEventos(){
btnBajar.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Message msg = new Message();
msg.setTarget(mHandler);
msg.obj = "TriggerMenu";
msg.sendToTarget();
}
});
vfPromociones.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(final View view, final MotionEvent event) {
detector.onTouchEvent(event);
return true;
}
});
objCrono.setOnChronometerTickListener(new OnChronometerTickListener() {
@Override
public void onChronometerTick(Chronometer chronometer) {
// TODO Auto-generated method stub
if (itiempo==2){
vfPromociones.showNext();
itiempo=0;
}else{
itiempo+=1;
}
}
});
}
这是我的日志
04-02 21:28:47.536: E/AndroidRuntime(17947): FATAL EXCEPTION: main
04-02 21:28:47.536: E/AndroidRuntime(17947): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.silice.qrstorecomerciales/com.silice.qrstore.AppController}: java.lang.NullPointerException
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.app.ActivityThread.access$700(ActivityThread.java:140)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.os.Handler.dispatchMessage(Handler.java:99)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.os.Looper.loop(Looper.java:137)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.app.ActivityThread.main(ActivityThread.java:4921)
04-02 21:28:47.536: E/AndroidRuntime(17947): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 21:28:47.536: E/AndroidRuntime(17947): at java.lang.reflect.Method.invoke(Method.java:511)
04-02 21:28:47.536: E/AndroidRuntime(17947): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
04-02 21:28:47.536: E/AndroidRuntime(17947): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
04-02 21:28:47.536: E/AndroidRuntime(17947): at dalvik.system.NativeStart.main(Native Method)
04-02 21:28:47.536: E/AndroidRuntime(17947): Caused by: java.lang.NullPointerException
04-02 21:28:47.536: E/AndroidRuntime(17947): at com.jesus.PrincipalPromociones.AfrmProciones.RegistrarEventos(AfrmProciones.java:116)
04-02 21:28:47.536: E/AndroidRuntime(17947): at com.jesus.PrincipalPromociones.AfrmProciones.onCreateView(AfrmProciones.java:96)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:523)
04-02 21:28:47.536: E/AndroidRuntime(17947): at roboguice.activity.RoboFragmentActivity.onStart(RoboFragmentActivity.java:53)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.app.Activity.performStart(Activity.java:5216)
04-02 21:28:47.536: E/AndroidRuntime(17947): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2083)
04-02 21:28:47.536: E/AndroidRuntime(17947): ... 11 more
我一直在寻找云,我找不到与此相关的任何内容。 事实上,在课堂上,如果他们扩展它会正确注入robofragmentactivity,一旦发生这种情况,robofragment就会停止为我工作。
是由于这个原因,我要留下设置?
感谢
答案 0 :(得分:1)
在RoboFragment中,视图以onViewCreated
方法注入。
之前调用了您的RegistrarEventos()
方法,因此当您尝试引用NullPointerException
视图时,您会收到btnBajar
。
注意:在Java中,习惯上使用小写的第一个字母和类的大写第一个字母命名方法