Java 带有AndroidAnnotations的运行时错误

Java 带有AndroidAnnotations的运行时错误,java,android,android-annotations,Java,Android,Android Annotations,我在我的应用程序中使用AndroidAnnotations,当我尝试在intent中添加额外内容并启动一个使用AndroidAnnotations的活动时,我总是会遇到运行时错误。当我停止使用AndroidAnnotations时,一切正常 以下是启动我的活动的代码: public class TimeAndDateShower extends Activity { //some code protected void onCreate(Bundle savedInstanceState) {

我在我的应用程序中使用AndroidAnnotations,当我尝试在intent中添加额外内容并启动一个使用AndroidAnnotations的活动时,我总是会遇到运行时错误。当我停止使用AndroidAnnotations时,一切正常

以下是启动我的活动的代码:

public class TimeAndDateShower extends Activity {
//some code

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.time_and_date_shower);
        //some code
        setButtonListener();

    }
public void setButtonListener()
    {
        Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener()
        {
          public void onClick(View v)
          {
              Intent intent = new Intent(TimeAndDateShower.this, DateChooser_.class);
              intent.putExtra("SSID", network);
              startActivity(intent);
              TimeAndDateShower.this.finish();
          }
        });
    }
}
以下是DateChooser.java的外观:

@EActivity(R.layout.date_chooser)
public class DateChooser extends Activity {

    public String network;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.date_chooser);

        setNetworkName();
        //some code   
    }

    public void setNetworkName()
    {
        TextView textView = (TextView)findViewById(R.id.textView4);
        network = this.getIntent().getStringExtra("SSID");//using an extra
        textView.setText(network);
    }

}
在AndroidManifest.xml中,我声明DateChooser活动如下:

name="com.componentix.imwizard.DateChooser_" android:screenOrientation="landscape"> </activity>

我猜您的NPE在textView上,这很正常:布局注入是在原始的
oncreate()
方法之后在生成的类中完成的。另外,你应该让AA为你注入额外的信息和视图。只需按如下方式更新您的类:

@EActivity(R.layout.date_chooser)
public class DateChooser extends Activity {

    @Extra("SSID")
    String network;

    @ViewById(R.id.textView4)
    TextView textView;

    @AfterViews
    void init() {
        textView.setText(network);
        //some code   
    }

}

你真的应该仔细看一下

我猜你的NPE在textView上,这很正常:布局注入是在原始的
oncreate()
方法之后在生成的类中完成的。另外,你应该让AA为你注入额外的信息和视图。只需按如下方式更新您的类:

@EActivity(R.layout.date_chooser)
public class DateChooser extends Activity {

    @Extra("SSID")
    String network;

    @ViewById(R.id.textView4)
    TextView textView;

    @AfterViews
    void init() {
        textView.setText(network);
        //some code   
    }

}

您应该仔细查看取消注释
setContentView(R.layout.date\u选择器)
根据日志,您有一个NPE,因此启动调试器(在第30行的
setNoteworkName()
中添加一个断点),并检查哪个对象不可用。你可以很容易地解决这个问题(或者提供更多细节,因为确实发生了一些事情)@Raghunandan为什么我需要这样做?我以为我已经将内容视图设置为@EActivity(R.layout.date\u chooser)@MykhailoGranik看看Uncomment
setContentView(R.layout.date\u chooser)
根据日志,您有一个NPE,因此启动调试器(在第30行的
setNoteworkName()
中添加一个断点),并检查哪个对象不可用。你可以很容易地解决这个问题(或者提供更多细节,因为确实发生了一些事情)@Raghunandan为什么我需要这样做?我想我已经用@EActivity(R.layout.date\u chooser)@MykhailoGranik设置了内容视图,看一看