22

I have a runtime error on my stock quoting application. I have an app where you input your a stock (as in stock market) code and will list it with two buttons. One button to display a quote and the other to view more info from the web. The web function is fine but the app crashes when I hit the quote button.

LogCat is asking me whether I declared my activity in my AndroidManifest.xml. I am still new to Android development so this is the best of which I can analyze the problem. I am not sure where to look for these errors.

Just use 'mstf' as a stock code if you need to test a fix.

You can find my app here: https://github.com/xamroc/StockQuote/tree/bug-quote

I would also appreciate any tips on debugging tools or techniques for Android.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Marco Lau
  • 579
  • 2
  • 10
  • 25
  • can you provide the manifest where you declare the activity – Ranjit Oct 01 '13 at 17:33
  • Are these similar? http://stackoverflow.com/questions/5734214/what-is-wrong-with-my-androidmanifest-xml http://stackoverflow.com/questions/7857015/activitynotfound-exception-thrown-for-preferenceactivity-listed-in-androidmanife http://stackoverflow.com/questions/15699192/have-you-declared-this-activity-in-your-androidmanifest-xml – dcanh121 Oct 01 '13 at 18:23

6 Answers6

38

You have two activities in your package, but have only declared one in manifest.

Declare the other Activity class:

Add this to your manifest:

<activity
     android:name="com.example.stockquote.StockInfoActivity"
     android:label="@string/app_name" />
Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
Manishika
  • 5,478
  • 2
  • 22
  • 28
  • Why is it necessary to register both activities? Are there any reasons? – ersks Jul 08 '16 at 08:57
  • Yes it is necessary to declare all the activities in manifest because it presents essential information about your app to the Android system, information the system must have before it can run any of the app's code. Check this Link for more info : https://developer.android.com/guide/topics/manifest/manifest-intro.html – Manishika Jul 11 '16 at 18:45
  • Thanks for delivering this information. I am researching about such matter & found match between your text & other researched matters. – ersks Jul 12 '16 at 10:44
18

Insert this <activity android:name=".StockInfoActivity" ></activity> in your AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.stockquote"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="18" />

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.example.stockquote.StockInfoActivity" >
        </activity>
    </application>

AndroidBegin.com
  • 402
  • 3
  • 10
2

so when ever you create a new class you have to create an activity in the "AndroidManifest.xml" file inside the application tag like this::

`

<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/AppTheme">
    <activity android:name=".mainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".loginActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

`

megh_sat
  • 374
  • 2
  • 12
1

Source: http://developer.android.com/guide/components/activities.html

You must declare your activity in the manifest file in order for it to be accessible to the system. To declare your activity, open your manifest file and add an <activity> element as a child of the <application> element. For example:

<manifest ... >
  <application ... >
      <activity android:name=".ExampleActivity" />
      ...
  </application ... >
  ...
</manifest >

There are several other attributes that you can include in this element, to define properties such as the label for the activity, an icon for the activity, or a theme to style the activity's UI.

The android:name attribute is the only required attribute—it specifies the class name of the activity. Once you publish your application, you should not change this name, because if you do, you might break some functionality, such as application shortcuts.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Touchstone
  • 5,575
  • 7
  • 41
  • 48
1

Your Activity means you have to declare your each and every class in android manifest so that it recognizes them as the Activity.So after the end of the Activity main you can do following:

<activity
 android:name=".YourClassNAME"

/>

Niroj
  • 1,114
  • 6
  • 29
1

you should declare the activity in manifest xml by defining the launchMode to singleTask or singleInstance.example:

<activity android:name="com.example.h.myapplication.MainActivity" 
          android:launchMode="singleTask" >

enter image description here

Srini
  • 489
  • 1
  • 11
  • 25
shadi
  • 21
  • 3