Не получается перейти на другое Activity. У меня есть ImageView с обработчиком нажатия.
private void initButton() {
ImageView button = (ImageView) findViewById(R.id.btn);
Glide.with(this)
.load(R.drawable.button)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.into(button);
}
public void onClick(View view) {
Intent intent = new Intent(Activity1.this, Activity2.class);
startActivity(intent);
}
Код первого Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
initBackground();
initButton();
initBackButton();
initHomeButton();
}
private void initBackground() {
ImageView background = (ImageView) findViewById(R.id.background);
Glide.with(this)
.load(R.drawable.background)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.centerCrop()
.into(background);
}
private void initButton() {
ImageView button = (ImageView) findViewById(R.id.btn);
Glide.with(this)
.load(R.drawable.button)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.into(button);
}
private void initBackButton() {
ImageView back_button = (ImageView) findViewById(R.id.btnBackToCategories);
Glide.with(this)
.load(R.drawable.arrow_back)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.into(back_button);
}
private void initHomeButton() {
ImageView home_button = (ImageView) findViewById(R.id.btnBackToHome);
Glide.with(this)
.load(R.drawable.home_button)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.into(home_button);
}
public void onBackClick(View view) {
Intent intent = new Intent(Activity1.this, CategoriesActivity.class);
startActivity(intent);
}
public void onHomeClick(View view) {
Intent intent = new Intent(Activity1.this, MainActivity.class);
startActivity(intent);
}
public void onClick(View view) {
Intent intent = new Intent(Activity1.this, Activity2.class);
startActivity(intent);
}
}
Код второго Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
initBackground();
initButton();
initBackButton();
initHomeButton();
}
private void initBackground() {
ImageView background = (ImageView) findViewById(R.id.background);
Glide.with(this)
.load(R.drawable.background)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.centerCrop()
.into(background);
}
private void initButton() {
ImageView skeleton_button = (ImageView) findViewById(R.id.btn);
Glide.with(this)
.load(R.drawable.skeleton_button)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.into(skeleton_button);
}
private void initBackToButton() {
ImageView back_button = (ImageView) findViewById(R.id.btnBackTo);
Glide.with(this)
.load(R.drawable.arrow_back)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.into(back_button);
}
private void initHomeButton() {
ImageView home_button = (ImageView) findViewById(R.id.btnBackToHome);
Glide.with(this)
.load(R.drawable.home_button)
.asBitmap()
.format(DecodeFormat.PREFER_ARGB_8888)
.into(home_button);
}
public void onBackClick(View view) {
Intent intent = new Intent(Activity2.this, Activity1.class);
startActivity(intent);
}
public void onHomeClick(View view) {
Intent intent = new Intent(Activity2.this, MainActivity.class);
startActivity(intent);
}
public void onClickSkeleton(View view) {
Intent intent = new Intent(Activity2.this, Activity3.class);
startActivity(intent);
}
}
Выдает такую ошибку:
08-11 10:13:11.809 26573-26573/com.levqo.project E/AndroidRuntime: FATAL EXCEPTION: main Process: com.levqo.project, PID: 26573 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.levqo.project/com.levqo.project.Activity2}: java.lang.IllegalArgumentException: You must pass in a non null View
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.IllegalArgumentException: You must pass in a non null View at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:678) at com.bumptech.glide.BitmapRequestBuilder.into(BitmapRequestBuilder.java:498) at com.levqo.project.Activity2.initButton(Activity2.java:40) at com.levqo.project.Activity2.onCreate(Activity2.java:20) at android.app.Activity.performCreate(Activity.java:5990) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Что делать?