Activity Declaration in AndroidManifest.xml

2019-01-04 03:39发布

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.

5条回答
干净又极端
2楼-- · 2019-01-04 03:48

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"

/>

查看更多
Melony?
3楼-- · 2019-01-04 03:53

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" />
查看更多
唯我独甜
4楼-- · 2019-01-04 03:57

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.

查看更多
Juvenile、少年°
5楼-- · 2019-01-04 04:05

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

查看更多
【Aperson】
6楼-- · 2019-01-04 04:06

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>

查看更多
登录 后发表回答