I created two activities, one MainActivity and the other is CookieActivity.I try to go to the cookie activity by clicking on the image from the main one, but the app crashes immediately after clicking.I am new to android development.Thanks for helping me with that!
my manifest file:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.applicationelharemelhazami"><application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.ApplicationElharemElhazami"><activity android:name=".CookieActivity"></activity><activity android:name=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>
The mainActivity:
package com.example.applicationelharemelhazami;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.ImageView;public class MainActivity extends AppCompatActivity { private ImageView play; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.play = (ImageView) findViewById(R.id.play); play.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent otherActivity = new Intent(getApplicationContext(), CookieActivity.class); startActivity(otherActivity); finish(); } }); }}
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"><TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/name_wahed" android:textColor="@color/red" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.525" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.702" /><ImageButton android:id="@+id/play" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/graven_logo" tools:layout_editor_absoluteX="11dp" tools:layout_editor_absoluteY="16dp" tools:ignore="MissingConstraints" /></androidx.constraintlayout.widget.ConstraintLayout>
CookieActivity :
package com.example.applicationelharemelhazami;//import android.support.v7.app.AppCompatActivity;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;public class CookieActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cookie); }}