使用RoboGuice 2注入活动视图时出错

时间:2013-06-27 20:30:17

标签: android roboguice

我在使用injectViewMembers注入视图时遇到问题,

错误我得到的是:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rgainternalapps.devicemanager/com.rgainternalapps.devicemanager.DeviceActivity}: java.lang.UnsupportedOperationException: internal error, how did you get here?

以下是相关代码:

public class DeviceActivity extends SherlockActivity {
RelativeLayout layout;
Device currentDevice;
ArrayList<User> assigneesList;
ProgressDialog progressDialog;

@Inject
DevicesHelpers devicesHelpers;

@Inject
DevicesData devicesData;

@Inject
UsersData usersData;

@InjectView(R.id.device_model)
TextView deviceModel;

@InjectView(R.id.name)
TextView name;

@InjectView(R.id.os)
TextView os;

@InjectView(R.id.version)
TextView version;

@InjectView(R.id.serial_number)
TextView serialNumber;

@InjectView(R.id.assign_to_me)
Button assignToMeButton;

@InjectView(R.id.owner_photo)
ImageView ownerPhoto;

@InjectView(R.id.owner_info)
RelativeLayout ownerInfo;

@InjectView(R.id.owner_name)
TextView ownerName;

@InjectView(R.id.owner_email)
TextView ownerEmail;

@InjectView(R.id.device_not_assigned)
TextView deviceNotAssigned;

@InjectView(R.id.device_assigned_to_you)
TextView deviceAssignedToYou;

@InjectView(R.id.assignee_selection)
LinearLayout assigneeSelection;

@InjectView(R.id.assign_to_other)
Button assignToOtherButton;

@InjectView(R.id.assignee_selector)
AutoCompleteTextView assigneeSelector;

User currentAssignee;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_device);

    //RoboGuice.injectMembers(this.getApplication(), this);
    //RoboGuice.getInjector(getApplicationContext()).injectMembersWithoutViews(this);
    RoboGuice.getInjector(getApplicationContext()).injectViewMembers(this);
}

}

另外,我试过

RoboGuice.injectMembers(getApplicationContext(), this);

但它似乎只注入了所有视图

我正在使用 RoboGuice 2.0 (roboguice-2.0.jar, guice-3.0-no_aop.jar).

Android SDK 4.1.2

我在Fragments中注入视图没有任何问题。

由于

巴勃罗

1 个答案:

答案 0 :(得分:0)

我不确定导致此错误的原因,但如果您想将ActionBarSherlock与RoboGuice一起使用,您可以查看 roboguice-sherlock 库。

在活动中插入RoboGuice需要比代码中显示的更多管道。例如,检查RoboSherlockActivity代码。

为了您的信息,RoboGuice.injectMembers()是执行标准 Guice 注入的重点,因此它不会处理@InjectView注释,因为它是特定于RoboGuice的。