Fragment is not assignable to android.app.Activity - android

Attempts to switch activities between two Android Fragments is failing.
This happens in spite of using the Android doco example verbatim:
Android Fragment doco
Attempts to add the target Fragment to the AndroidManifest.xml does not compile with the same message that is in the Title of this question.
If I hack the same process using only Views and straight Activities the all is well.
If I leave the AndroidManifest.xml unchanged then I get a run-time exception with the question:
android.content.ActivityNotFoundException: Unable to find explicit activity class {name.davidwbrown.actionbartabs/name.davidwbrown.actionbartabs.UserDetailsFragment}; have you declared this activity in your AndroidManifest.xml?

Try defining an xml layout containing the fragment instead of assigning it to the <activity> tag on the manifest. Then use findViewById(R.id.frameId) to find it in code and then attach it to the activity. In the manifest, keep the activity tag something similar to this and it should work:
<activity
android:name="name.davidwbrown.actionbartabs.UserDetailsFragment"
android:label="#string/activity_name" >
</activity>

Maybe you should try changing your Fragment class to a FragmentActivity class.

Related

Having an error that Unable to find explicit activity class (startactivity from activity to fragment)

my startactivity(i_back) has a problem , I am trying to startactivity from activity to fragment. so there is no need to declare in manifest since it is fragment so I don't know why I have the error Thx in advance
You must declare activity (inside <application> tag) in manifest like that:
<activity android:name=".addressbook.ContactsFragment"/>
If your class ContactsFragment extends Fragment, you can't start it using startActivity method.
Check the docs on how to deal with fragments.
https://developer.android.com/guide/components/fragments
If your class ContactsFragment extends Activity, you must declare it in AndroidManifest.xml inside application tag, just like that.
<activity android:name=".ContactsFragment"/>
Check if your class is inside any package.

Android.Content.ActivityNotFoundException: Unable to find explicit activity class {} have you declared this activity in your AndroidManifest.xml?

Android.Content.ActivityNotFoundException: Unable to find explicit activity class {AgLiveMobile.Droid/aglivemobile.droid.views.NewDemoView};
have you declared this activity in your AndroidManifest.xml?
I am implementing Drawer menu and referring
https://github.com/benhysell/V.FlyoutTest
I am getting this error on following line :
this.ShowViewModel<NewDemoViewModel>();
I have also given full path as follows in the xml file :
<activity
android:name="aglivemobile.droid.views.NewDemoView">
</activity>
What does it mean? What should I do to resolve this?
Thanks in advance
Maybe you need to check that you added the new activity to the manifest.xml file
or
The activity you are calling should appear not only in the Manifest for its own package, but in the Manifest for the CALLING package, too.
Probably, you have to add presenter (if you don't have) to Setup for Android. Something like that:
protected override IMvxAndroidViewPresenter CreateViewPresenter()
{
var mvxFragmentsPresenter = new MvxFragmentsPresenter(AndroidViewAssemblies);
Mvx.RegisterSingleton<IMvxAndroidViewPresenter>(mvxFragmentsPresenter);
return mvxFragmentsPresenter;
}

Android activity not found in android manifest

Trying to open an activity, the debugger launches en exception:
11-29 14:54:02.750: E/AndroidRuntime(26008): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.solinpromex.casajuventudtrescantos/com.solinpromex.casajuventudtrescantos.Calendario_Agenda_Activity}; have you declared this activity in your AndroidManifest.xml?
But I think the mentioned activity is already in my AndroidManifest.xml:
<activity
android:name=".com.solinpromex.casajuventudtrescantos.Calendario_Agenda_Activity"
android:label="Agenda">
</activity>
and it is inside the tag
Any help is welcome...
You must either remove leading dot from android:name or change the name to not include package name:
android:name
The name of the class that implements the activity, a
subclass of Activity. The attribute value should be a fully qualified
class name (such as, "com.example.project.ExtracurricularActivity").
However, as a shorthand, if the first character of the name is a period (for example, ".ExtracurricularActivity"), it is appended to
the package name specified in the element.
Docs here.

How to modify androidmanifest.xml to use a class that extends ListActivity?

I have two classes one that extends Activity and inside that class file I called another intent which class extends ListActivity. How do I change the androidmanifest.xml file to load that two activities? I should say that I declared both of the activities in androidmanifest.xml file as
<activity android:name="NoteActivity"></activity>
<activity android:name="AddNote"></activity>
the NoteActivity extends Activity and the AddNote extends ListActivity; when I run it it doesn't run and said "stopped" unfortunately.
You need to define your newly created activities in manifest too. So simply update your AndroidManifest.xml at least as minimum as below:
<activity android:name=".NoteActivity" android:label="Activity1" />
<activity android:name=".AddNote" android:label="Activity2" />
*It is assumed that your activity files are placed in root of your package as defined in manifest and make sure the class names are correctly depicted in the xml above.
Note: Make sure your activity starts with a dot (.) symbol too.

android.content.ActivityNotFoundException:

I am getting this exception while I am trying to call an activity from another one. The complete exception is
android.content.ActivityNotFoundException:Unable to find explicit activity class {com.x.y/com.x.y.class};
I am doing an intent.setClass("com.x.y","com.x.y.className") where className is the name of my activity class and com.x.y is the package it resides in.
My AndroidManifest.xml has the following content:
<activity android:name="com.x.y.className" android:label="#string/app_name">
Am I missing anything?
Maybe you need to check that you added the new activity to the manifest.xml file
Example:
<activity
android:name=".className"
android:label="#string/app_name" >
</activity>
If other people are encountering something similar and arrive at this post, an issue I had may save you some time. May not be related to the OP's problem but def related to the ActivityNotFound exception.
I was trying to load an activity by using:
Intent intent = new Intent( this, class );
However I continuously kept getting the ActivityNotFoundException even though I had checked and rechecked the code multiple times.
This exception I was getting wasn't actually being caused by the intent but some code I was running inside the loaded activity throwing a RuntimeException. (my issue was caused by Typeface.createFromAsset())
It is possible you are running into a similar RuntimeException in your activity.
To see if this is the case, put your intent code in try catch blocks. Like so:
try {
/* your code */
...
} catch ( ActivityNotFoundException e) {
e.printStackTrace();
}
Run your app again, and check your LogCat, if it's the same issue, you'll get a RuntimeException with a "Caused By:" entry pointing to your actual issue.
I spent a good hour trying to figure this out. Hopefully this may save someone some time.
The activity you are calling should appear not only in the Manifest for its own package, but in the Manifest for the CALLING package, too.
Delete your activity from the manifest and then add it again. This type do not write type the XML directly. Instead, go to Application > Application nodes > add, choose the Activity, and then browse for the file source.
This worked for me.
intent.setClass takes parameters as "Package Context" and "Class".
an example would be:
intent.setClass(CurrentActivity.this, TargetActivity.class);
also you need to check if the activity is registered in manifest file.
Added a new activity and defined it in manifest.xml, but I was still getting "Unable to find explicit activity class" error. I am using Eclipse. Solution for my problem was "cleaning" the project. From the main menu in Eclipse: Project|Clean.... Then you select your project and clean it.
Hey, you need to use another form of Intent constructor. This will surely solve your issue within a second:
Example:
Intent inte=new Intent(getBaseContext(),"your class name with .class extension ");
startActivity(inte);
This works perfectly and I checked this code, its working properly.
I had an ActivityNotFoundException when I implemented the Activity inside another class (as an inner class):
//... inside the utility class Pref
public static class Activity extends PreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
}
}
//...
Declared as the following inside the manifest:
<activity android:name=".Pref.Activity"
...
After declaring this as a normal class (public class PrefActicity) and changing manifest accordingly, it worked as usual.
I was using getActivityContext() (instead of Activity.this) for the menu code to save some work, and copy-and-paste it to each activity without editing each time.
I replaced them with Activity.this, and the issue is gone.
I have a feeling a smarter Android guy could work-around not having to do that. Would like to hear what it would be.
Looking at the documentation here what you want is:
intent.setClassName("com.x.y", "className");
Restart the Eclipse and check your Manifestfile again. If you find missing the respective Activity, then add it and try again. It solved my similar issue.
In addition to Mina's answer.
When you declare activity as inner static class then you should write your activity into manifest like ...
<activity android:name=".app.FragmentLayoutSupport$DetailsActivity" />
here .app comes from your package name , it can be .helpers.afdfa$afda
My solution to this error was to add a package name in front of the name in manifest.
I had the following activities:
id.scanner.main.A1
id.scanner.main.gallery.A2
My manifest contained the following:
<activity android:name=".A1" ....></activity>
<activity android:name=".A2" ....></activity>
This solved the problem:
<activity android:name=".A1" ....></activity>
<activity android:name="gallery.A2" ....></activity>
Yeah I got this problem too. I refreshed the project. And then, everything works fine.
when i have same issue. if you are using library class files and writing it into android manifest files write it like and then remove the library projects manifest files this portion>>
then it will work absolutely..
This exception also occurs if you include a library in your app and if the library is calling an activity defined in the library project. In this case we need to merge library's manifest with calling app's manifest.
With ADT version 20, we can do this by adding the below statement in project.properties of calling app.
manifestmerger.enabled=true
Check out the content of the Android Manifest File in the bin folder of the project. When your app is compiled and packaged the Manifest File is copied to the bin folder. In my case the Manifest in the bin folder did not agree with the original Manifest. This is probably a mistake of Eclipse. I manually copied the Manifest to the bin folder and it worked.
you can add this code in manifiest.xml file
action android:name="com.kaushalam.activity101activity.SecondActivity"
category android:name="android.intent.category.DEFAULT"
I got the same case too. After reading thepearson's answer, I revised my Activity and found out that I wrote
public void onCreate(Bundle s)
But in fact it should be
protected void onCreate(Bundle s)
And it works now!
This works if you have an Activity object (which you need to launch):
intent.setClassName(CallingActivity.this, activityToLaunch.getComponentName().getClassName());
Activity you're calling sholdn't contain "sheme" and contain intent-filter:
<activity android:name=".SecondActivity">
<intent-filter>
<action android:name="com.example.sj.myapplication.SecondActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
so in calling code:
Intent intent=new Intent("com.example.sj.myapplication.SecondActivity");
startActivity(intent);
Try using the following:
intent.setClassName("com.x.y", "com.x.y.className");
This works for me
I also ran into ActivityNotFoundException by passing the wrong view into setContentView(), each activity's class file must correspond with the layout xml file this way.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wrongView);
}
as opposed to
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.correctView);
}
I had the same issue. I tried everything but the error, which I sorted out later, was that there was a space left between double quotes and my class name. It has to be:
intent.setClassName("com.x.y","com.x.y.className")
not
intent.setClassName("com.x.y"," com.x.y.className")

Categories

Resources