Loading fragment from ListView's ItemClick listener - android-listview

I have one Fragment Activity which contains the listview. On click of the ListView's Items i want to load a fragment and close the Fragment activity.
I have tried to implement as below but getting the error of FrameLayout id where i am trying to load Fragment.
Logcat:
09-03 16:49:57.321: E/AndroidRuntime(1740): FATAL EXCEPTION: main
09-03 16:49:57.321: E/AndroidRuntime(1740): java.lang.IllegalArgumentException: No view found for id 0x7f0a0045 (com.zeal.peekaboo:id/fragmentswitcherframe) for fragment OtherProfileFragment{4a31cb00 #0 id=0x7f0a0045}
09-03 16:49:57.321: E/AndroidRuntime(1740): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
09-03 16:49:57.321: E/AndroidRuntime(1740): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
09-03 16:49:57.321: E/AndroidRuntime(1740): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
09-03 16:49:57.321: E/AndroidRuntime(1740): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
09-03 16:49:57.321: E/AndroidRuntime(1740): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
09-03 16:49:57.321: E/AndroidRuntime(1740): at android.os.Handler.handleCallback(Handler.java:587)
09-03 16:49:57.321: E/AndroidRuntime(1740): at android.os.Handler.dispatchMessage(Handler.java:92)
09-03 16:49:57.321: E/AndroidRuntime(1740): at android.os.Looper.loop(Looper.java:123)
09-03 16:49:57.321: E/AndroidRuntime(1740): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-03 16:49:57.321: E/AndroidRuntime(1740): at java.lang.reflect.Method.invokeNative(Native Method)
09-03 16:49:57.321: E/AndroidRuntime(1740): at java.lang.reflect.Method.invoke(Method.java:521)
09-03 16:49:57.321: E/AndroidRuntime(1740): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-03 16:49:57.321: E/AndroidRuntime(1740): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-03 16:49:57.321: E/AndroidRuntime(1740): at dalvik.system.NativeStart.main(Native Method)
Listview ItemClick
m_lvList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adptr, View view, int pos,
long id) {
m_slistItemId = String.valueOf(m_lookArryList.get(pos)
.getM_userId());
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment llf = new OtherProfileFragment();
ft.replace(R.id.fragmentswitcherframe, llf);
ft.commit();
finish();
}
});
Please guide me for this. I am not able to understand what is going wrong?
Any help will be appreciated.
Thanks.

"I am not able to understand what is going wrong?"
If I understand this correct, then you load a Fragment in the layout of your FragmentActivity and close this Activity immediately after the commit() for the transaction with finish().
I don't know what you try to achieve but you will never see that Fragment. It will be destroyed when the Activity is destroyed, which happens because of the finish() call. This behavior is part of the Fragment lifecycle. A Fragment can't exist alone, only with an Activity as host.
You get that error, because the commit() call for the Fragment transaction is async. Means that the Activity and the layout is closed through finish(), but the commit() of the transaction will still try to load the Fragment to the layout.
Edit:
If you wanna finish() the Activity, which holds the ListView, pass the results to another Activity via Intent. In this Activity build your View with the desired Fragment and hand it the results.
Maybe you wanna have a look at the Master Detail Flow Pattern, which is exactly for that use case. The Tutorial uses the standard template of Eclipse. You can get the idea out of it and modify it.

Related

Event$ object was thrown resolving an image frame: [object Event]

======== Exception caught by image resource service ================================================
The following Event$ object was thrown resolving an image frame:
[object Event]
When the exception was thrown, this was the stack:
Image provider: NetworkImage("https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.vecteezy.com%2Ffree-vector%2Fprofile-avatar&psig=AOvVaw2GefCTODTxsxVvzrV4lp5z&ust=1674463308057000&source=images&cd=vfe&ved=0CBAQjRxqFwoTCKCf94fk2vwCFQAAAAAdAAAAABAE", scale: 1)
answer for this========
That link does not point to an image, but to a Google redirection page which points to an image-search page. You must provide a single image URL to the NetworkImage instance.

Wicket ajax call failes after opening page in another tab

I have a wicket application. The application is basically a single page application and everything is done using ajax calls. I have a requirement to open a piece of information in another tab or window. There are several ways to do so, using html
target = "_blank"
or using code via PopupSettings. All these work in way that they open the new page/tab with the data I need.
The problem is that when I click on an ajax action on the origin page, after opening the other window/ tab, I get an error saying the component belongs to a different page. After debugging I understand that once I call the new page, my old page is no longer stored in the page store manager cache. What happens is that on request commit (which is called at the end of the request cycle) the following is called on org.apache.wicket.page.PageStoreManager:
public synchronized void setSessionCache(final List<IManageablePage> pages) {
sessionCache = new ArrayList<>(pages);
afterReadObject = null;
}
with the "pages" list argument holding a single page, the new page, thus replacing the current page in the cache. Once I call the the ajax call, instead of receiving the page from cache I receive a deSerialized version of the page from the store which is a different instance then the one connected to the component used for the click behaviour, and I get the error.
Am I doing something wrong? Is this a bug? an architectural flow? Appreciate any light shed on this.
I'm using wicket 8.9.0
Here is the call to the page to render on a new tab. currently it is on a non ajax button inside the page:
protected void onClick() {
UserSession.get().setAttribute(Constants.documentRef, obj);
this.setResponsePage(DocumentViewPage.class);
}
The button tag has target="_blank".
Here is the error I get:
ava.lang.IllegalArgumentException: Component [RealmPanel [Component id = realm]] cannot be updated because it is on another page.
at org.apache.wicket.page.PartialPageUpdate.add(PartialPageUpdate.java:451)
at org.apache.wicket.ajax.AjaxRequestHandler.add(AjaxRequestHandler.java:241)
at org.apache.wicket.ajax.AjaxRequestHandler.add(AjaxRequestHandler.java:234)
at com.centimia.smartAdmin.frame.controller.Navigator.updateRealm(Navigator.java:474)
at com.centimia.smartAdmin.frame.controller.Navigator.setCurrentPanel(Navigator.java:249)
at com.emi.client.main.panel.folder.FolderMenuProvider$3.onClick(FolderMenuProvider.java:179)
at com.centimia.smartAdmin.frame.component.menu.MenuItem$1.onClick(MenuItem.java:76)
at org.apache.wicket.ajax.markup.html.AjaxLink$1.onEvent(AjaxLink.java:85)
at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:127)
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:598)
at org.apache.wicket.core.request.handler.ListenerRequestHandler.internalInvoke(ListenerRequestHandler.java:306)
at org.apache.wicket.core.request.handler.ListenerRequestHandler.invoke(ListenerRequestHandler.java:280)
at org.apache.wicket.core.request.handler.ListenerRequestHandler.invokeListener(ListenerRequestHandler.java:222)
at org.apache.wicket.core.request.handler.ListenerRequestHandler.respond(ListenerRequestHandler.java:208)
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:914)
at org.apache.wicket.request.RequestHandlerExecutor.execute(RequestHandlerExecutor.java:65)
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:282)
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:253)
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:221)
at org.apache.wicket.protocol.ws.AbstractUpgradeFilter.processRequestCycle(AbstractUpgradeFilter.java:70)
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:206)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:299)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1602)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1588)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1557)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:502)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)

ATG Rest full API addItemToOrder is not working

I am working on ATG Web-commerce REST Full API, addItemToOrder is not working.
This is the Error:
{
"formError": true,
"formExceptions": [
{
"localizedMessage": "Unable to process the request currently. Please try again after some time",
"errorCode": "atg.droplet.DropletException"
}
],
"concurrentUpdate": false
}
http://IP:Port/rest/model/atg/commerce/order/purchase/CartModifierActor/addItemToOrder
I have checked the server log file, Null pointer exception is showing.
/atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler --- java.lang.NullPointerException
**** Error /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler at atg.siebel.catalog.SiebelCatalogTools.updateQuoteWithProfileDetails(SiebelCatalogTools.java:3681)
/atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler at atg.siebel.catalog.SiebelCatalogTools.checkProductEligibility(SiebelCatalogTools.java:3384)
/atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler at atg.siebel.validation.SiebelValidator.validateProductEligibility(SiebelValidator.java:141)
/atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler at atg.siebel.order.purchase.SiebelCartModifierFormHandler.preAddItemToOrder(SiebelCartModifierFormHandler.java:569)
/atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler at atg.commerce.order.purchase.CartModifierFormHandler.handleAddItemToOrder(CartModifierFormHandler.java:3035)
/atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
/atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
/atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
/atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-143/atg/commerce/order/purchase/CartModifierFormHandler at java.lang.reflect.Method.in
(there are more lines of error Unable to post here),
Would it be because of product sync issue? or sku's issue..?
Please help
Still a bit difficult to work out exactly where the error is but considering that you are calling the updateQuoteWithProfileDetails(Quote,RepositoryItem) method and in the calling method there is a null check on the RepositoryItem (profile) and Quote is new, then the only line that could end up with a NullPointerException in the calling code is:
parentOrganizationOfProfile = (RepositoryItem) profile.getPropertyValue(getProfilePropertyParentOrganization());
Which means that the ProfileParentOrganisation value on the profile RepositoryItem is null.
The rest of the code in that method (according to the source provided by ATG in the reference application) all provide null checks.

Zend Feed Import Exception Handling

I have a php code written in Zend Framework to import RSS Feeds from URLS.
Here is my code:
$slashdotRss = Reader::import($url);
It works fine on
http://iafrica.tv/feed
But gives error on
http://iafrica.tv
Error is given below:
#0 C:\xampp\htdocs\AveroxProjects\BleupageDev\vendor\zendframework\zend-feed\src\Reader\Reader.php(250): Zend\Feed\Reader\Reader::importString('')
#1 C:\xampp\htdocs\AveroxProjects\BleupageDev\module\Bleupage\src\Bleupage\Model\rssFeed.php(17): Zend\Feed\Reader\Reader::import('http://iafrica....')
Message
Only non empty strings are allowed as input
My question is how I can handle this exception so that a proper message is displayed to user instead of the error without turning off exception.

Redirecting in #PostConstruct method resulted in IllegalStateException

According to the answer of BalusC, I used
FacesContext.getCurrentInstance().getExternalContext().redirect(url);
in my #PostConstruct method to stop JSF from rendering the view and redirect users. However, when I try to run the code, I still ran into the java.lang.IllegalStateException exception at the above line.
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:524)
at StudentManagedBean.CourseSummary.init(CourseSummary.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
UPDATE: I added the following line in my #PostConstruct method:
System.out.println("INIT " + FacesContext.getCurrentInstance().getExternalContext().isResponseCommitted());
and what I saw was INIT true. I wonder if the response is supposed to be committed BEFORE the #PostConstruct method is called?
I'd be very grateful if you could give me an advice.
As mentioned in my update, the following line printed INIT true:
System.out.println("INIT " + FacesContext.getCurrentInstance().getExternalContext().isResponseCommitted());
I finally found why the above situation occurred. On my page, before the ManagedBean X, which contains the redirect function, was referenced by UIComponent A, another ManagedBean Y was referenced beforehand by UIComponent B that is placed above UIComponent A in the page structure. As a consequence, the response was partially committed by ManagedBean Y, which makes it impossible for ManagedBean X to send a redirect request.
A redirect will not work here, because even though the response has been completed and finalized, JSF is not smart enough to avoid its typical routine of running through the lifecycle events anyway.
Instead you can try doing a Forward from a RequestDispatcher. A Forward is different from a redirect in the following ways:
Performed internally by the servlet
Browser is apathetic
original url stays intact
Here is some code that displays how this can be done...
RequestDispatcher dispatcher =
((ServletRequest) context.getExternalContext().getRequest())
.getRequestDispatcher("/j_spring_security_logout");
try {
dispatcher.forward((ServletRequest) context.getExternalContext().getRequest(),
(ServletResponse) context.getExternalContext().getResponse());
} catch (ServletException e) {
log.error("ServletException", e);
} catch (IOException e) {
log.error("IOException", e);
}
By doing this you are ending the execution of the FacesServlet prematurely and forwarding it onto a different servlet altogether. I imagine that from this other servlet it might be possible to redirect to the desired location.