0

I have MainActivity and trying to extend this activity to create About Us page for users. I have text About Us on menu when clicked to open the extended activity.

Here is the XML for About Us page:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:gravity="center_horizontal"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Maihan Nijat is making app."
                android:id="@+id/textView" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

And the extended About Us Activity

public class AboutUs extends ActivityMain {

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

And this is how I linked:

else if (id == R.id.nav_about) {
   Intent i = new Intent(getApplicationContext(), AboutUs.class);
   startActivity(i);
}

I have imported all the required importings.

When I run the app and click on the About Us it says "unfortunately the app has stopped'

Log Cat:

     Process: com.revittechnology.pashtodictionary, PID: 25122
                                                                                           android.content.ActivityNotFoundException: Unable to find explicit
activity class
 {com.revittechnology.pashtodictionary/com.revittechnology.pashtodictionary.AboutUs};
 have you declared this activity in your AndroidManifest.xml?
                                                                                               at
 android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1794)
                                                                                               at
 android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
                                                                                               at android.app.Activity.startActivityForResult(Activity.java:3917)
                                                                                               at android.app.Activity.startActivityForResult(Activity.java:3877)
                                                                                               at
 android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
                                                                                               at android.app.Activity.startActivity(Activity.java:4200)
                                                                                               at android.app.Activity.startActivity(Activity.java:4168)
                                                                                               at
 com.revittechnology.pashtodictionary.ActivityMain.onNavigationSelected(ActivityMain.java:148)
                                                                                               at
 com.revittechnology.pashtodictionary.ActivityMain$2.onNavigationItemSelected(ActivityMain.java:94)
                                                                                               at
 android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:150)
                                                                                               at
 android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
                                                                                               at
 android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
                                                                                               at
 android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
                                                                                               at
 android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:308)
                                                                                               at android.view.View.performClick(View.java:5198)
                                                                                               at android.view.View$PerformClick.run(View.java:21147)
                                                                                               at android.os.Handler.handleCallback(Handler.java:739)
                                                                                               at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                               at android.os.Looper.loop(Looper.java:148)
                                                                                               at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                                               at
 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
Maihan Nijat
  • 9,054
  • 11
  • 62
  • 110

4 Answers4

1

you are initializing a textview in a wrong way.

parent_view = findViewById(android.R.id.textView); //here

instead cast the view to a proper textview class

parent_view = (TextView)findViewById(android.R.id.textView); //here must be cast

verify aswell if you have declared your AboutUs activity in the app manifest.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
1

Check your AndroidManifest.xml is like this,

<manifest xmlns:android="http://schemas.android.com/apk/res/android"  
    package="com.javatpoint.hello"  
    android:versionCode="1"  
    android:versionName="1.0" >  

    <uses-sdk  
        android:minSdkVersion="8"  
        android:targetSdkVersion="15" />  

    <application  
        android:icon="@drawable/ic_launcher"  
        android:label="@string/app_name"  
        android:theme="@style/AppTheme" >  
        <activity  
            android:name=".MainActivity"  
            android:label="@string/title_activity_main" >  
            <intent-filter>  
                <action android:name="android.intent.action.MAIN" />  

                <category android:name="android.intent.category.LAUNCHER" />  
            </intent-filter>  
        </activity>
            <activity  
            android:name=".Aboutus"  
            android:label="@string/title_aboutus" >  
        </activity>
    </application>  
</manifest>  
Ronak Joshi
  • 1,553
  • 2
  • 20
  • 43
1

Please ADD AboutUs to your AndroidManifest.xml.

This is error because you dont have declared activity in AndroidManifest.

ADD like

<activity  
android:name=".AboutUs"  
android:screenOrientation="portrait" />

Please check add activity manifest stack answer

Community
  • 1
  • 1
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
1

I'm assuming About us is another activity. In that case you need to extend your About Us class to either Activity or AppCompatActivity(if you want backward compatibility).

Shashank Udupa
  • 2,173
  • 1
  • 19
  • 26