这是我的mvp模块
@Module
public class LoginModule {
@Provides
public LoginPresenterImpl providePresenter(LoginView loginView , LoginInteractor loginInteractor) {
return new LoginPresenterImpl(loginView,loginInteractor);
}
@Provides
public LoginView loginView(){
return new LoginActivity();
}
@Provides
public LoginInteractor loginInteractor(Repository repository){
return new LoginInteractorImpl(repository);
}
@Provides
public Repository provideRepository(APIInterfaces.LoginInterface loginInterface){
return new Repository(loginInterface,loginView());
}
@Provides
public LoginPresenter loginPresenter(APIInterfaces.LoginInterface loginInterface){
return providePresenter(loginView(),loginInteractor(provideRepository(loginInterface)));
}
}
这是我的登录活动
{
ProgressHUD progressHUD;
private LinearLayout main_layout;
private boolean flag = false;
private EditText email_edt, password_edt;
private ImageView login_btn;
private TextView sign_up_tv, forget_password_tv;
@Inject
public LoginPresenter loginPresenter;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//getWindow().setStatusBarColor(Color.TRANSPARENT);
// flag = getIntent().getBooleanExtra("from_splash", false);
// loginPresenter = new LoginPresenterImpl(this,new LoginInteractorImpl());
MyApplication.getComponent().inject(this);
setControls();
} // onCreate()
@Override
protected void onDestroy() {
loginPresenter.onDestroy();
super.onDestroy();
}
private void setControls() {
main_layout = findViewById(R.id.main_login_layout);
email_edt = findViewById(R.id.edt_txt_email);
password_edt = findViewById(R.id.edt_txt_password);
sign_up_tv = findViewById(R.id.sign_up_txt);
forget_password_tv = findViewById(R.id.forget_password_txt);
login_btn = findViewById(R.id.login_btn);
login_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loginPresenter.validateEmailPassword(email_edt.getText().toString().trim(),password_edt.getText().toString().trim());
}
});
sign_up_tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
loginPresenter.openRegistrationPage();
}
});
forget_password_tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
if(flag)
Logging.Snackbar(main_layout, getString(R.string.check_internet_msg));
} // setControls()
@Override
public void showProgress() {
//progressHUD = ProgressHUD.show(LoginActivity.this, getString(R.string.loading_txt), false, null, null);
}
@Override
public void hideProgress() {
//progressHUD.dismiss();
}
@Override
public void passwordError(int x) {
switch (x)
{
case 0 :
password_edt.setError(getString(R.string.password_length_error_msg));
break;
case 1 :
password_edt.setError(getString(R.string.empty_field_error_msg));
break;
}
}
@Override
public void emailError(int y) {
switch (y)
{
case 0 :
email_edt.setError(getString(R.string.empty_field_error_msg));
break;
case 1 :
email_edt.setError(getString(R.string.invalid_email_error_msg));
break;
case 2 :
email_edt.setError(getString(R.string.invalid_email_error_msg));
break;
}
}
@Override
public void openRegistration() {
Intent intent = new Intent(LoginActivity.this, RegistrationActivity.class);
startActivity(intent);
finish();
}
@Override
public void forgetPassword() {
}
@Override
public void navigateToHome(Response<LoginResponse> response) {
if (response.body().getError() == 0 && response.body().getMessage().equalsIgnoreCase("Login Success"))
{
UserData userData = new UserData();
Intent intent = new Intent(this,MainPageActivity.class);
userData = response.body().getData();
intent.putExtra("UserData",userData);
startActivity(intent);
finish();
}
else
{
Logging.Toast(this,response.body().getMessage());
}
}
@Override
public void onError() {
Logging.Toast(this,"Check Your Internet Connection");
}
}
当我尝试导航到主页活动LoginActivity.this返回null如何解决这个问题。 这是我得到的错误 java.lang.NullPointerException:尝试调用虚方法&#39; java.lang.String android.content.Context.getPackageName()&#39;在null对象引用上 在android.content.ContextWrapper.getPackageName(ContextWrapper.java:141)
答案 0 :(得分:0)
我通过编辑MVP模块解决了这个问题
reviewer_demographics_residence_state reviewer_link attr_name review_rate dummy
greece 1 uffizi 1.0 1
greece 1 uffizi2 4.0 2
greece 2 uffizi 2.0 3
greece 3 uffizi 2.5 4
greece 4 uffizi 2.5 4
italy 2 uffizi 3.0 3
公共类LoginModule {
@Module
}
并为其创建活动范围