I started my android studio and when I ran my app, I get a lot of error comming from drawable.java. For example, in the following piece of drawable.java I got:
NonNull, TRACE_TAG_RESOURCES, traceBegin, traceEnd, insets,
DENSITY_DEVICE, noncompatDensityDpi and getOpticalInsets all shows the
error "cannot resolve symbol" or "cannot resolve method".
public boolean getPadding(#NonNull Rect padding) {
padding.set(0, 0, 0, 0);
return false;
}
public Insets getOpticalInsets() {
return Insets.NONE;
}
public void getOutline(#NonNull Outline outline) {
outline.setRect(getBounds());
outline.setAlpha(0);
}
public Drawable mutate() {
return this;
}
public void clearMutated() {
// Default implementation is no-op.
}
public static Drawable createFromStream(InputStream is, String srcName) {
Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, srcName != null ? srcName : "Unknown drawable");
try {
return createFromResourceStream(null, null, is, srcName);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
}
}
public static Drawable createFromResourceStream(Resources res, TypedValue value,
InputStream is, String srcName) {
Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, srcName != null ? srcName : "Unknown drawable");
try {
return createFromResourceStream(res, value, is, srcName, null);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
I have never even touched drawable.java and I did not even know it ever existed. I tried cleaning up the project but nothing has changed. Is there any solution to this problem?
On Android Studio try to go to:
File -> Invalidate Caches/Restart -> Invalidate & restart.
As far as I can guess that, you've done something wrong with you layout or xml files. Please check if all the layouts are error free.
I would like to suggest a TODO list for you so that you look for all the reasons which might create this type of error.
Check all the layout files for errors.
Check all the drawables.
Check if any layout file name contains any capital letter.
Check if any image file name contains any capital letter.
If everything is okay, then do a clean and rebuild the application.
Related
I need to detect when a file (of any type) is opened in Eclipse and run some code when that happens.
I've tried with the following code but it seems to be calling the function multiple times:
Display.getDefault().asyncExec(new Runnable() {
#Override
public void run() {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(new IPartListener2() {
#Override
public void partOpened(IWorkbenchPartReference partRef) {
System.out.println("File opened");
}
});
}
});
Is there a way to do this in Eclipse RCP?
IPartListener2.partOpened is the correct thing to use. Make sure you only set up the listener once.
partOpened will be called for all parts, so you will need to check for the ones you are interested in.
#Override
public void partOpened(final IWorkbenchPartReference partRef)
{
// Check for editor reference and get the editor part
if (partRef instanceof IEditorReference &&
partRef.getPart(false) instanceof IEditorPart editorPart) {
// Example getting current IFile being edited:
IFile file = editorPart.getEditorInput().getAdapter(IFile.class);
}
}
Note: Example code uses Java 16 type pattern, for older releases it will need revising.
Also note Display.asyncExec is not usually needed to set this up.
I got this error:
java.lang.IllegalStateException: Fragment already added: MenuBottomSheetFragment{d476429 #0}
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1891)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:760)
My code when open clicked MenuBottomSheetFragment:
private void openBottomSheet() {
if (mMenuBottomSheetFragment == null)
mMenuBottomSheetFragment = new MenuBottomSheetFragment();
if (!mMenuBottomSheetFragment.isShowing())
mMenuBottomSheetFragment.show(getSupportFragmentManager(), mMenuBottomSheetFragment.getTag());
}
And my MenuBottomSheetFragment have nothing special.
I really have no idea why. Most of the time, MenuBottomSheetFragment works fine. But some time, it throws this Exception then I do nothing.
So what is the problem in my case? And how can I fix it?
Replace the isShowing with this:
if(!mMenuBottomSheetFragment.isAdded()) {
mMenuBottomSheetFragment.show(getSupportFragmentManager(), mMenuBottomSheetFragment.getTag());
}
The fragment has already been added. There is no need to show it again. Just check it after the null-check and return if it's added:
if(mMenuBottomSheetFragment.isAdded()) {
return;
}
Is there a switch/flag that allows to do this? I spent hours finding those but couldn't find anything that works. The other thing I'm planning to do is intercept the cefRequest by adding my own CefRequestHandler, examine the resource type and if it matches RT_IMAGE, cancel the request. Everything seems easy except the part when I have to cancel a request. How do I stop/block/cancel a cefRequest? I probably should not be doing it this way but it doesn't work anyway:
public class CefClientRequestHandler extends CefRequestHandlerAdapter {
#Override
public boolean onBeforeResourceLoad(CefBrowser cefBrowser, CefFrame cefFrame, CefRequest cefRequest) {
if (cefRequest.getResourceType().equals(CefRequest.ResourceType.RT_IMAGE)) {
cefRequest.setURL("");
}
return false;
}
// more overides
}
Any ideas?
So here's a hack that works. The trick is to change the Request Method to HEAD, and because HEAD requests aren't returned the body, images won't be part of the response.
public class CefClientRequestHandler extends CefRequestHandlerAdapter {
#Override
public boolean onBeforeResourceLoad(CefBrowser cefBrowser, CefFrame cefFrame, CefRequest cefRequest) {
if (cefRequest.getResourceType().equals(RT_IMAGE)) {
cefRequest.setMethod("HEAD");
}
return false;
}
// other overridden methods here...
}
I believe that this approach should be avoided mainly because of the following two reasons:
Changing the method from GET to HEAD does not prevent CEF from making the request to the server. The overhead of opening a connection and handling a request is still there which makes it slower than simply blocking the request.
I'm not sure if images won't be displayed if they are available from browser cache. Currently, I don't know of any methods to test this. Suggestions are welcome.
Edit 1:
Changing URL didn't work in the example I posted in the question because I was passing an empty String as the new URL. If we set the URL to some address that is not an "active" domain name (e.g. https://absolutegarbage-sdjdjfbskdfb.com), the request for that resource fails immediately:
#Override
public boolean onBeforeResourceLoad(CefBrowser cefBrowser, CefFrame cefFrame, CefRequest cefRequest) {
if (cefRequest.getResourceType().equals(CefRequest.ResourceType.RT_IMAGE)) {
cefRequest.setURL("https://yghjbnbk.com");
System.out.println("LOL!");
}
return false;
}
As you can probably guess, this still is not the best solution. Please post an answer or comment if someone has found a better solution.
Edit 2: Finally I have a clean working solution, thanks to user amaitland. We just have to pass a command line switch while setting the CefAppHandler. We can do that by overriding the method onBeforeCommandLineProcessing like this:
CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
#Override
public void onBeforeCommandLineProcessing(String s, CefCommandLine cefCommandLine) {
cefCommandLine.appendSwitch("disable-image-loading");
}
#Override
public void stateHasChanged(CefApp.CefAppState state) {
if (state == CefApp.CefAppState.TERMINATED) System.exit(0);
}
});
i've got some problem with my Mouse Cursor. I set it inside my MouseMotion Event of a JPanel with this.setCursor(), but it dosen't changed.
After getting out ouf the Window for example on my Desktop and go back inside , the cursor will be changed by any motion.
The Code of the mouse Event of the JPanel is this:
public void mouseMoved(MouseEvent e) {
this.requestFocusInWindow();
this.requestFocus();
this.cL.doMouseMoved(e);
}
The Code of the Method doMouseMoved is this:
public void doMouseMoved(MouseEvent e) {
this.lastMouseEvent = e;
this.sList.setCurrentElements(e.getPoint());
this.setMovedCursor(e);
}
An finally this is the code of the method setMovedCursor:
public void setMovedCursor(MouseEvent e) {
java.awt.Cursor cu = new java.awt.Cursor(java.awt.Cursor.SW_RESIZE_CURSOR);
view.setCursor(cu);
}
(I know that this isn't the best way)
I hope everyone can help me.
Sorry for any mistakes, it's my first post at stackoverflow.
if (sList.getCurrentShapeType() == "rec") {
Not sure if it will fix your problem but don't use "==" to compare objects.
Instead you should be using the equals(...) method.
if ("rec".equals(sList.getCurrentShapeType()) {
Note: I changed the order of the test so you don't have to worry about the getCurrentShapeType() method returning a null value.
else if (k.getBorderByPoint(e.getPoint()) == 4)
Also, I don't know what your getBorderByPoint() method does but why are you comparing it to an integer value. We have no idea what "4" means. Don't use "magic numbers. Instead create variables like: CURSOR_NORTH. Or better yet why not just return the cursor from that method so you don't have to check the value twice.
I got the task to migrate to wicket 1.4 to wicket 1.5. Despite lack of information in migration guide I was somehow able to refactor most issues. Unfortunetly I'm stuck with "resource" - atm I'm getting this error
java.lang.IllegalArgumentException: Argument 'resource' may not be null.
What I understand by that is that something was change and wicket can no longer "get" to my resources. So I used to have (in wicket 1.4) that piece of code that was responsible for creating image and passing it (the method is in class that extends WebPage) :
private void addImageLogo() {
Resource res = new Resource() {
#Override
public IResourceStream getResourceStream() {
String logo = ConfigurationManager.getInstance().getPathValue(ConfigurationManager.LOGO_FILE_PATH);
return new FileResourceStream(new File(logo));
};
Image logo = new Image("logo", res);
add(logo);
}
Now Resource class no longer exists or I can't find it. While searching internet I was able to change it into this
private void addImageLogo() {
String logoTxt = ConfigurationManager.getInstance().getPathValue(ConfigurationManager.LOGO_FILE_PATH);
ResourceReference res = new ResourceReference(logoTxt) {
#Override
public IResource getResource() {
return null;
}
};
Image logo = new Image("logo", res);
add(logo);
}
This is responsible for obtaining path (and its working): ConfigurationManager.getInstance().getPathValue(ConfigurationManager.LOGO_FILE_PATH)
Unfortunetly I'm still getting this error that I mentioned above. The method getResource() generated automaticly and I believe this is an issue because I'm retuning null but I have no idea what (or how) should I return.
Since it worked with a IResourceStream in 1.4.x then you can just use org.apache.wicket.request.resource.ResourceStreamResource as a IResource for the Image.
Your first code snippet is not complete so I cannot give you exact replacement code.