Search code examples
androidandroid-activity

error when going from 1st activity to 2nd activity


I'm new to Andriod programming and I would like to go from the 2nd activity to the 3rd but it doesn't work because the application stops. Here is the error:

android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class Linearlayout

I don't understand because I did the same to move from the main activity to the first and everything worked. Here is my code:

-first_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FirstActivity">>

<Button
    android:id="@+id/first_activity_next_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Next" />    
</RelativeLayout>

-first_activity.java

public class FirstActivity extends AppCompatActivity {

private Button nextButton;

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

    nextButton = (Button) findViewById(R.id.first_activity_next_btn);

    nextButton.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){
            Intent secondActivity = new Intent(FirstActivity.this, SecondActivity.class);
            startActivity(secondActivity);
        }
    });

    }
}

-second_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<Linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
tools:context=".SecondActivity">>

<TextView
    android:id="@+id/activity_main_title_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="30dp"
    android:text="2nd activity"/>
</Linearlayout>

-second_activity.java

public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second_activity);
    }
}

Need help please


Solution

  • You have a typo in your code. Change Linearlayout to LinearLayout in your Second Activity's layout file