“Activity not found” in Android

后端 未结 7 1408
后悔当初
后悔当初 2021-01-24 23:04

I am using the navigation-drawer template in eclipse to do a simple Android application. I have some trouble with fragment. I declared a fragment called PresenceL

相关标签:
7条回答
  • 2021-01-24 23:17

    Please open the manifest file and declare like this:

    <activity
            android:name=".MainActivity" //your activity name
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    

    if this is your lauch activity then do this otherwise do this

    <activity
            android:name=".MainActivity"//your activity name
            android:label="@string/app_name" >
        </activity>
    

    type the name of your java file which extends Activity not the Fargment. Means the Fragment which creates from that Activity java file.

    0 讨论(0)
  • 2021-01-24 23:19
     have you declared this activity in your AndroidManifest.xml?  
    

    Look in your manifest and see if you have an <activity> element that has your activity registered. If not, add one.

    Have a look here: http://developer.android.com/guide/topics/manifest/activity-element.html

    0 讨论(0)
  • 2021-01-24 23:21
     <activity
            android:name="com.singtel.ricecooker.PresenceLogFragment"
            android:label="@string/app_name" >
        </activity>
    

    add this in your manifest file if com.singtel.ricecooker.PresenceLogFragment represents an activity and if it is a fragment then you are doing it wrong. in second case use below code,

    getSupportFragmentManager()
    .beginTransaction()
    .replace(R.id.content_frame, new PresenceLogFragment())
    .commit();
    
    0 讨论(0)
  • 2021-01-24 23:24

    You have created a Fragment so you could not call it like a Activity. You need to replace a container view, properly an FrameLayout with your Fragment.

    getSupportFragmentManager()
      .beginTransaction()
      .replace(R.id.content_frame, new PresenceLogFragment())
      .commit();
    
    0 讨论(0)
  • 2021-01-24 23:40

    it is clear.

    "have you declared this activity in your AndroidManifest.xml?"

    you should check is there a tag。

    see this or maybe this

    0 讨论(0)
  • 2021-01-24 23:40

    You are trying to use a fragment as an activity. You can either rename PresenceLogFragment to PresenceLogActivity and have it extend Activity instead of Fragment or you can try and use your fragment as a fragment.

    Also, any activity you try to use in your app needs to be declared in the manifest (link)

    More about fragments and how to use them here

    0 讨论(0)
提交回复
热议问题