Rare exception "Unable to find explicit activity class" - android-activity

I know there are a few questions about "Unable to find explicit activity class" that happens consistently. My case is different. The code usually works flawlessly. The exception is thrown only occasionally:
Intent intent = new Intent(this, UpgradeActivity.class);
intent.putExtra(UpgradeActivity.GOOGLE_APP_PUBLIC_KEY, sKey);
startActivity(intent);
Yes, the activity is declared in AndroidManifest.xml. It is in a library in the same project as the app.
The exception:
Exception: Unable to find explicit activity class {net.mydomain.myapp/net.mydomain.android.UpgradeActivity}; have you declared this activity in your AndroidManifest.xml?
Class: android.content.ActivityNotFoundException
Stack trace: android.content.ActivityNotFoundException: Unable to find explicit activity class {net.mydomain.myapp/net.mydomain.android.UpgradeActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2256)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1914)
at android.app.Activity.startActivityForResult(Activity.java:5326)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:647)
at android.app.Activity.startActivityForResult(Activity.java:5284)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:628)
at android.app.Activity.startActivity(Activity.java:5670)
at android.app.Activity.startActivity(Activity.java:5623)
Could anyone offer a tip on the possible cause of this rare exception?

Related

How can I throw exception in subprocess in Drools jbpm?

I have several custom WorkItemHandlers, and handle the exception by using handleException(e);
public abstract class AbstractItemHandler extends AbstractLogOrThrowWorkItemHandler implements WorkItemHandler
But I found a very strange thing, if the custom WorkItemHandler is in subprocess, there will be no exception when calling kieSession.startProcess(MAIN_PROCESS_ID, processMap).
It works when there is only one process(bpmn). But when there are more bpmn files, I found the ProcessInstance is return abnormal state.
Assert.assertEquals(ProcessInstance.STATE_ABORTED, processInstance.getState());

Autofac An error occurred during the activation of a particular registration

I have inherited a .NET project which keeps throwing Autofac errors but I'm not sure what this error message is telling me. Any help would be appreciated?
An error occurred during the activation of a particular registration. See the inner exception for details.
Registration:
Activator = ImplementationResourceRepository (ReflectionActivator),
Services = [Interfaces.IImplementationResourceRepository],
Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime,
Sharing = None,
Ownership = OwnedByLifetimeScope ---> None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'CCES.Repositories.ImplementationResourceRepository' can be invoked with the available services and parameters:
Cannot resolve parameter 'Interfaces.IRepository repository' of constructor 'Void .ctor(Interfaces.IRepository)'. (See inner exception for details.)
Type ImplementationResourceRepository has a constructor that takes an instance that implements Interfaces.IRepository in it's constructor but no types were registered as Interfaces.IRepository. You need to register a type that implementats Interfaces.IRepository as that interface with Autofac.
Something similar to this:
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<Implementations.Repository>()
.As<Interfaces.IRepository>()
.InstancePerDependency();
}

Autofac doesnot cannot resolve types when in IIS sub application

Does any one know why autofac fails to initialize the mvc controllers when there is an applicaton in the root and also another in sub application in IIS? How to fix this?
When the apps are hosted in different Websites in IIS they work without a problem.
so in the image, the root app(mvc web) deployed in the root works but not the webservice (mvc api).
error is
An error has occurred.An error occurred when trying to create a controller of type 'UserController'. Make sure that the controller has a parameterless public constructor.System.InvalidOperationException at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()An error has occurred.An exception was thrown while invoking the constructor 'Void .ctor()' on type 'BurpDaddyEntities'. ---> The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. (See inner exception for details.)Autofac.Core.DependencyResolutionException at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters)
While the top-level exception appears to be from Autofac, if you look down at the inner exception issue that caused the whole thing, you'll see the true exception is The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. Which means the static constructor for that class went awry.
Fortunately, there's actually a question (with an answer!) directly about exactly what you're facing here with nested websites using Entity Framework:
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception on a Sub Website

Sharprepository Autofac InstancePerApiRequest in Webapi environment not working

Does anyone have a working example of sharprepository intergration with autofac using InstancePerApiRequest for DbContext?
I am registering my dbcontext thusly:
builder.RegisterType<AuditTestEntities>().As<DbContext>().InstancePerApiRequest();
If I remove the InstancePerApiRequest, sharprepository is able to get a dbcontext. But with the InstancePerApiRequest, I get the error message pasted below. Basically the crux of the error is, I suspect, the way sharprepository makes the call:
No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.
The full error stack:
iisexpress.exe Error: 0 : Operation=DefaultHttpControllerActivator.Create, Exception=System.InvalidOperationException: An error occurred when trying to create a controller of type 'AccountController'. Make sure that the controller has a parameterless public constructor. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor()' on type 'AccountRepository'. ---> Could not resolve type 'System.Data.Entity.DbContext' using the 'AutofacDependencyResolver'. Make sure you have configured your Ioc container for this type. View the InnerException for more details. (See inner exception for details.) ---> SharpRepository.Repository.Ioc.RepositoryDependencyResolverException: Could not resolve type 'System.Data.Entity.DbContext' using the 'AutofacDependencyResolver'. Make sure you have configured your Ioc container for this type. View the InnerException for more details. ---> Autofac.Core.DependencyResolutionException: No scope with a Tag matching 'AutofacWebRequest' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.
Okay found the issue. There is a problem with using the SharpRepository AutofacDependencyResolver when using the MVC or Web API integration and trying to use the scope InstancePerApiRequest or InstancePerHttpRequest. Autofac expects those items to be resolved from the System.Web.DependencyResolver.Current instead of from the Autofac IContainer directly as the AutofacDependencyResolver is currently doing.
Here is how you can fix the issue right now until we make an overload for AutofacDependencyResolver that fixes the issue.
You will need to create your own dependency resolver within your project like this one:
public class CustomAutofacDependencyResolver : BaseRepositoryDependencyResolver
{
private readonly IDependencyResolver _resolver;
public CustomAutofacDependencyResolver(IDependencyResolver resolver)
{
_resolver = resolver;
}
protected override T ResolveInstance<T>()
{
return _resolver.GetService<T>();
}
protected override object ResolveInstance(Type type)
{
return _resolver.GetService(type);
}
}
And then register it with SharpRepository so it will use it to resolve the DbContext and then it will work as expected.
RepositoryDependencyResolver.SetDependencyResolver(new CustomAutofacDependencyResolver(DependencyResolver.Current));
** Update**
I was testing with MVC and able to replicate the error and fix it but that doesn't work with Web API. I am used to using StructureMap where it works fine using the GlobalConfiguration.Configuration.DependencyResolver.
It seems the issue is that Autofac needs a IDependencyScope that you can access from the HttpRequestMessage but I'm not seeing a way to get to that outside of the ApiController. This describes the issue and the reason: https://groups.google.com/forum/#!msg/autofac/b3HCmNE_S2M/oMmwFE5uD80J
Unfortunately right now I'm at a bit of a loss on the best way to handle this. But I'll keep thinking about it.
So, I was able to get mine working by changing the lifetime scope to InstancePerLifetimeScope. I don't know whether this has any unforeseen consequences or not. Everything appears to be working fine for me so far.

Persisting Classes implementing an interface with GORM MongoDB Plugin

I am having a problem while persisting a class. I have a class called Scraper which uses an interface called Paginator. There are several implementations of the Paginator interface which will be instantiated at runtime. So the structure looks like this:
class Scraper {
//some code
Paginator paginator
//more code
def Scraper(Paginator paginator){
this.paginator = paginator
}
}
and then there are the concrete implementations of the paginator interface lets say paginatorA and paginatorB. So now I am trying to do the following:
PaginatorA p = new PaginatorA()
Scraper s = new Scaper(p)
s.save(flush:true)
...and what it get is:
Error Error executing script TestApp:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': Cannot resolve reference to bean 'mongoMappingContext' while setting bean property 'mappingContext';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext': FactoryBean threw exception on object creation; nested exception is java.lang.NullPointerException (Use --stacktrace to see the full trace)
Can anybody tell me what to make of this? I guess it has something to do with the Mapper because it doesn't know which concrete Paginator to use or how to persist it? If that is the case then how can I tell the framework what to do? I tried to come up with a solution for hours now and am really frustrated so any help would be really really appreciated.
Oh btw I also tried implementing against the concrete implementation (PaginatorA) ... this works perfectly fine since my assumption that it has something to do with the paginator interface.
Thanks for any response...
The error is bad, you should probably raise a JIRA issue for that, but fundamentally there are 2 problems I can see with the code:
Your persistent classes must have a public no-args constructor as per any JavaBean, by adding a constructor that takes your interface, you are no longer providing one
Your Scraper class needs to mark the 'Paginator' as transient to tell the persistence engine not to attempt to persist the 'paginator' property. Since this a custom interface it will not know how to persist it.