-2

MainActivity is not working. I tried to run it on Emulator but the application is forced to stop. I'm trying to jump from MainActivity to UserActivity

MainActivity.java

package com.example.kanishk.coachingfinder;

    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button clickHere = (Button)findViewById(R.id.clickHere);
    clickHere.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent mainIntent = new Intent(MainActivity.this,UserActivity.class);
            startActivity(mainIntent);
        }
    });
}
}

LogCat (Arguments are on next line in many lines of codes)

 04-12 03:44:51.709 4607-4607/com.example.kanishk.coachingfinder 
E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.kanishk.coachingfinder, PID: 4607
java.lang.RuntimeException: Unable to start activity 
 ComponentInfo{com.example.kanishk.coachingfinder/
com.example.kanishk.coachingfinder.MainActivity}: 
android.view.InflateException: Binary XML file line #10: Error inflating 
class ImageView
    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)

Below is activity_main.xml file. I am not able to find out the problem in it.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:background="#ccd9ff"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.kanishk.coachingfinder.MainActivity">

<ImageView
    android:layout_width="385dp"
    android:layout_height="305dp"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:scaleType="centerCrop"
    android:src="@mipmap/cfinder"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.888"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView3"
    app:layout_constraintVertical_bias="0.161" />



<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="Welcome to"
    android:textAlignment="center"
    android:textAppearance="@style/TextAppearance.AppCompat"
    android:textColor="#91b4ff"
    android:textSize="35sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0"
    tools:ignore="MissingConstraints" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="364dp"
    android:layout_height="96dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="COACHING FINDER"
    android:textAlignment="center"
    android:textColor="#ff7f50"
    android:textSize="40sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2"
    app:layout_constraintVertical_bias="0.0"
    tools:ignore="MissingConstraints" />

<Button
    android:id="@+id/clickHere"
    style="@style/Widget.AppCompat.Button.Colored"
    android:layout_width="79dp"
    android:layout_height="55dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="132dp"
    android:text="CLICK HERE"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.427"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView3"
    app:layout_constraintVertical_bias="0.018" />


</android.support.constraint.ConstraintLayout>

2 Answers2

1

I suspect that this is due to a configuration issue in your XML layout. This issue had a similar exception:

InflateException: Binary XML file line #8: Error inflating class ImageView

I would check the source of your image, whether it exists in the correct location and what the file format is.

Also posting the XML would help a lot in debugging.

Shawn
  • 402
  • 4
  • 17
0

While I'm not entirely sure what you're trying to do, try doing this:

Intent mainIntent = new Intent(getApplicationContext(), UserActivity.class);

Here's my resource, since I've done this before: https://www.youtube.com/watch?v=6ow3L39Wxmg

Skip to about 21:45 to take a look at a similar line of code.

Ben
  • 13
  • 7