1

我在从我的片段 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 就会停止为我工作。

是因为这个我留下了设置吗?

谢谢

4

1 回答 1

1

在 RoboFragment 中,视图被注入到onViewCreated方法中。

RegistrarEventos()在此之前调用您的方法,因此NullPointerException当您尝试引用btnBajar视图时会得到一个。

注意:在 Java 中,习惯上使用小写首字母命名您的方法,类的首字母大写

于 2013-04-02T20:35:18.953 回答