Reputation: 25877
Initially my Android project had only one activity named MainActivity
. Then, I added a new activity named ChildActivity
into my project. I'm trying to launch my new activity as startup activity when app gets launched. I changed AndroidManifest.xml
file to achieve it. I moved the entire intent-filter
tag from MainActivity
to ChildActivity
as shown below:
<activity android:name=".MainActivity">
</activity>
<activity android:name=".ChildActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Layout file of ChildActivity
looks like this. I'm trying to show a TextView
on the new activity I've just added:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.FrameLayout 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=".ChildActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_display"
android:text="Hello this is Rasik!"/>
</android.support.constraint.FrameLayout>
ChildActivity.java file:
package com.example.android.explicitintent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class ChildActivity extends AppCompatActivity {
private TextView mDisplayText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child);
}
}
Whenever I try to debug my app in Android AVD, nothing happens. It seems my app is crashing at start up. Can anyone help me in diagnosing the root cause?
Upvotes: 0
Views: 521
Reputation: 117
The Root layout android.support.constraint.FrameLayout
you are using does not exist. Check out this link Android Developer guide.
Your Root layout can be:
There are many layouts available which you can use based on your need.
Upvotes: 1
Reputation: 2955
You used wrong layout. Just convert android.support.constraint.FrameLayout to FrameLayout. Or convert to default android.support.constraint.ConstraintLayout
<FrameLayout
...>
<TextView
...
/>
</FrameLayout>
Upvotes: 1
Reputation: 2785
The class android.support.constraint.FrameLayout
not exists. Try LinearLayout
, FrameLayout
, android.support.constraint.ConstraintLayour
or others
Upvotes: 2
Reputation: 780
please try this !
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_display"
android:text="Hello this is Rasik!"/>
</FrameLayout>
i think there is issue with root framelayout
Upvotes: 2
Reputation: 1
I had seen a similar issue in another post. Just off the bat, it seems like your child activity is not within the enclosing terms of the ".MainActivity."
Put the child activity into the brackets of the ".MainActivity", in between the
<activity android:name=".MainActivity"> </actvitiy>
. Hopefully that makes it run better. If that doesn't work, start the child activity during the onCreate() method of the MainActivity.
Upvotes: 0