The hierarchy of the type AddEntryAction is inconsistent (Jface) - jface

i have the following class in eclipse
class AddEntryAction extends Action {
public AddEntryAction() {
super("Add Entry");
setToolTipText("Add Entry");
}
public void run() {
WizardDialog dlg = new WizardDialog(MainClass.mainWindow.getShell(),
new AddEntryWizard());
dlg.open();
}
}
and Action class extends AbstractAction which intern extends EventManager class. Both these parent classes are part of the eclipse SWT/jface libraries... I get the following error on the above class declaration
The project was not built since its
build path is incomplete. Cannot find
the class file for
org.eclipse.core.commands.common.EventManager.
Fix the build path then try building
this
project DisplayExample Unknown Java
Problem
The type
org.eclipse.core.commands.common.EventManager
cannot be resolved. It is indirectly
referenced from required .class
files MainClass.java /DisplayExample/src line
94 Java Problem
AddEntryAction is declared within the same source file MainClass.java. Actually, this is an example from Java2s.com ... I have the libraries/jars because i can see the compiles classes of all these clases

The error "The project was not built since ... org.eclipse.core.commands.common.EventManager cannot be resolved..." with swt/jface dependencies can be caused by missing reference sources or binaries containing org.eclipse.core packages in addition to org.eclipse.swt and org.eclipse.jface packages.
E.g. build path in my case included:
swt.jar
org.eclipse.jface_3.4.2.M20090107-0800.jar
Following jar was missing and caused above error:
org.eclipse.core.commands_3.4.0.I20080509-2000.jar

Related

Specify class loader for loading dependencies of an advice's dependency

I have an advice class that makes use of another class that's part of the agent jar, but this other class has a dependency on a class that's not present in the agent jar. This class that's not present in the agent jar is present in another jar that's on the application class loader. The agent jar is on the system class loader. So I run into NoClassDefFoundError. I have tried using Transformer.ForAdvice as suggested in this other post, but that only works for the advice class.
// In agent jar on system class loader
MyAdviceClass {
#Advice.OnMethodEnter
public static void onMethodEnter() {
YetAnotherClass.doSomething(); // works fine as Transformer.ForAdvice makes use of the correct class loader while inlining this code
AnotherClass.doSomething(); // NoClassDefFoundError happens inside this method call
}
}
// In agent jar on system class loader
public class AnotherClass {
public static void doSomething() {
YetAnotherClass.doSomething(); // NoClassDefFoundError happens here because the system class loader is used to load YetAnotherClass, but that class is only present on the application class loader
}
}
// In user jar on application class loader
public class YetAnotherClass {
public static void doSomething() {
// do something else
}
}
Transform looks like this:
.transform(new AgentBuilder.Transformer
.ForAdvice()
.include(getClass().getClassLoader())
.advice(methodMatcher, "com.something.advice.MyAdvice.class"));
MyAdviceClass and AnotherClass are present in the agent jar. YetAnotherClass is present in user jar that's not on the system class loader, its on the application class loader. How can I solve this problem? i.e. is there a way by which I can force the use of the application class loader in AnotherClass?
I assume that AnotherClass is not visible from the class being instrumented. In this case, you should not include the class in ypur agent jar but place it in a seperate jar that you append to the boot loader via Instrumentation.appendToBootSearchPath. Classes on the boot loader are universally visible and should therefore be accessible to your instrumented class.
If the injected classes reference classes of the instrumented class loader you might however need to inject classes into the class loader using a ClassInjector.

Dealing with R8 + JvmStatic Annotation + Lambda in public API for Android Library written in Kotlin

First of all, please note that I'm not expecting why do you want to obfuscate library comments. This is a genuine problem I'm asking about.
I have been having an issue dealing with R8/obfuscation with an Android library written in Kotlin.
I've a public API method which is annotated with #JvmStatic and that method takes a Lambda as parameter.
For example, take a look at code below,
typealias MyLambdaCallback = (String, Map<String, Any>) -> Unit
#Keep
object MyApi {
private var callback: MyLambdaCallback? = null
#JvmStatic
fun setCallback(callback: MyLambdaCallback) {
this.callback = callback
}
}
I have added #Jvmstatic so that Java calling code can call the method statically rather than doing MyApi.INSTANCE.setCallback()
When I release the library without minification, everything is fine and calling code from both Java and Kotlin is written as expected.
But now I want to release the library while turning on minification.
That creates an issue.
Here is the error
java.lang.IncompatibleClassChangeError: The method 'void setCallback(kotlin.jvm.functions.Function2)' was expected to be of type virtual but instead was found to be of type static (declaration of 'com.demo.basic.Application' appears in /data/app/com.demo.basic-_0uJXPbtfs3UZ2Rp2h-RdQ==/base.apk!classes2.dex)
Am I making a mistake somewhere or this is expected as some kind of limitation ?
What did I Try ?
Removing #Jvmstatic resolves the issue but it created ugly Java calling code
Kept #Jvmstatic but removed Lambda converting Lambda into an interface with one method and everything is working fine. Unfortunately SAM for Kotlin classes is not there yet, so calling Kotlin code looks ugly.
This is tracked on the R8 issue tracker http://issuetracker.google.com/158393309 which has more details.
The short story is that this has been fixed in R8 version 2.1.35, which can be used by making the following changes to the top level build.gradle file:
repositories {
maven {
url 'https://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:2.1.35' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
}
R8 team has fixed this issue along with related issue b/158400283 in R8 version 2.1.42
Fix should already be available in Android Studio 4.1 beta or higher, but if you're using stable Android Studio 4.0 then add following to your top-level build.gradle file:
buildscript {
repositories {
maven {
url 'https://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:2.1.42' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
}
}

Static Library C++/WinRT

I have created a static library(c++/WinRT) and an Universal Windows App [Blank App] (c++/WinRT)project in VS 2019.
Then From Project Universal Window app I added project reference of the static library.
I am getting below error while building the universal app
D:\Dv\Main\Vib\CM\UI\UserInterfaceCppWinRT\Generated Files\XamlTypeInfo.g.cpp(178,52): error C2039: 'UIViewModelCppWinRT': is not a member of 'winrt'
Individually the static library build successfully. Not getting any clue about c++/winrt static library project consumption. Any suggestion?
When you add reference of the static library to main project and build main project successfully, you can find it has generated the StaticLibrary.h file under the \MyProject\MyProject\Generated Files\winrt folder along with other Windows namespaces. So if you want to import the idl(e.g. Class.idl), you don't need to import it manually, since your toolchain is set up to automatically reference any types that are in system namespaces. You only need to import any types that you've defined in your project. For example:
MainPage.idl
namespace WinrtApp
{
[default_interface]
runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
{
MainPage();
Int32 MyProperty;
StaticLibrary1.Class MyClass;
}
}
When you want to access the property from static library, first include the header file and initialize it.
MainPage.h
private:
StaticLibrary1::Class myclass{nullptr};
.cpp:
#include "winrt/StaticLibrary1.h"
myclass = StaticLibrary1::Class();
int property = myclass.MyProperty();
Here is a simple sample that I created, you can download it to check the complete steps.

Lambda expression not working with IntelliJ

Im trying to use the IntelliJ IDE to write a JavaFX program, however when the lambda expression is used, I get an error message followed by a compile error
original code
error message
Overrides method in javafx.event.EventHandler
package sample;
import javafx.application.Application
import javafx.scene.control.*;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage window) throws Exception {
window.setTitle("Window Title");
Button button = new Button("Click me");
button.setOnAction(e -> System.out.println("Hello World"));
}
}
compile error
To specify, it is set up as a JavaFX program, in project structure I have the Project SDK set to 10.0.1 and I have the language level set to 8
Is there something missing that I need in order to use lambda expressions?
Change the project language level to 10:
On your application folder build.gradle Add compileOptions inside android:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_10
targetCompatibility JavaVersion.VERSION_1_10
}
}
I had the same problem.
Indeed under File > Project Structure > modules, the Language level was set to 7 - Diamonds, RM, multi catch.
But since the project is built with maven, the root problem was located in maven pom.xml
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
just set the value to 1.8 and the problem is solved.

PHP/Laravel can not resolve parent Class

Using php 7, Laravel 5.5. All models are in default app/ folder, Prototype is in app/ folder too. Nothing was moved
What is most frustrating - this worked all right for controllers (everything is in their default folders)
My Prototype Class:
class Prototype extends Model
{
//other code
}
My child Class:
class Tree extends Prototype
{
//other code
}
Exception:
include(/var/www/html/app/Prototypephp): failed to open stream: No such file or directory
I need help to fix this issue. Thanks!
After a few hrs of working over this issue solved it by moving Prototype Class to other namespace (and folder). Did the same to PrototypeController for code readability.