First run Intellij+AspectJ ,hava a lot of errors - java

I am trying to use AspectJ in sample project in IntelliJ IDEA. I have an experience with Spring AOP, but this is first time I am using AspectJ, and cannot make it work.
Environment:Win 10, IntelliJ IDEA and AspectJ,
Refer to this document for configuration,
https://www.jetbrains.com/help/idea/2016.3/aspectj.html
public class Hello {
public void sayHello() {
System.out.println("test1.Hello, AspectJ!");
}
public static void main(String[] args) {
Hello hello = new Hello();
hello.sayHello();
}
}
public aspect TxAspect {
void around():call(void Hello.sayHello()){
System.out.println("Start transaction...");
proceed();
System.out.println("end transaction...");
}
}
It should hava outputs:
Start transaction...
Hello, AspectJ!
end transaction...
but it appears a lot of errors:
enter image description here

Change the jdk release from 10 to 8 can solve this problem.

Related

Separate main() methods to run DesktopLauncher.main() and Server using Libgdx and Kryonet

I want my GameServer to run separately from the game itself. So, players(clients) can join into one static GameServer and I can handle them together and see how many clients are connected, currently.
But the problem is, I can only run only one of these classes(GameServer.main() and DesktopLauncher.main()) at the same time. GameServer must be running always at the background if I'm not wrong, right ? Yet, I can't run the game itself without stopping the GameServer. (It stucks saying Executing task 'DesktopLauncher.main()'...) I have some pictures to realize what's going on and what project structure looks like :
Pic 1 , Pic 2 , Pic 3
Here is my project structure :
core
-java
--com.mygdx.game
---Multiplayer
----Packets
-----GameClient.java
-----GameServer.java
-----GameClientListener.java
-----GameServerListener.java
---screens
---utils
---Application.java
GameServer.class
package com.mygdx.game.Multiplayer;
imports..
public class GameServer {
public int TCP_PORT,UDP_PORT;
public Server server;
public GameServerListener listener;
public static int totalClients = 0;
public GameServer() {
TCP_PORT = UDP_PORT = xxxx;
server = new Server(TCP_PORT,UDP_PORT);
listener = new GameServerListener(this);
startServer();
}
public void startServer() {
server.addListener(listener);
try {
server.bind(TCP_PORT,UDP_PORT);
//server.bind(TCP_PORT);
} catch (IOException e) {
e.printStackTrace();
}
registerPackets();
server.start();
}
private void registerPackets() {
server.getKryo().register(LoginRequest.class);
server.getKryo().register(LoginResponse.class);
server.getKryo().register(ChoiceRequest.class);
server.getKryo().register(ChoiceRespond.class);
}
public static void main(String[] args) {
new GameServer();
}
}
Thanks for any help.
Had the same issue. Downgrading to Android Studio 3.4 worked for me.
Check: https://www.reddit.com/r/libgdx/comments/fxrlsm/unable_to_run_two_or_more_application_in_parallel/

I/O using windowbuilder in eclipse for a java application

I've never used java windowbuilder before, however I'm trying to test it with my program which performs operations on sets. It's a Gradle project. I wrote all classes in the default package (I knew that it's discouraged just when I was finished). The program reads a line of operations on sets, parses it and prints the result and keeps doing that while there is a new line input from the user.
I'm trying to make a simple GUI for this program using windowbuilder but I can't figure out how to run the main class in the windowbuilder class and make it take input from a jtextfield and prints output.
My main looks like this:
public static void main(String[] argv) {
new Main().start();
}
private void start() {
hmap = new HashMap<IdentifierInterface, SetInterface<BigInteger>>();
Scanner in = new Scanner(System.in);
// While there is input, read line and parse it.
while (in.hasNextLine()) {
try {
String statement = in.nextLine();
if (statement.trim().isEmpty()) {
System.out.println("error, no statement");
} else {
Scanner statementScanner = new Scanner(statement);
readStatement(statementScanner);
}
} catch (APException e) {
System.out.printf("%s\n", e.getMessage());
}
}
}
I made a new windowbuilder class, with the buttons and text fields, but I got stuck on how to run my main inside the windowbuilder. Your help is appreciated. Thanks in advance.
Eclipse RCP applications are OSGi plug-ins; they do not have a main() method.
Instead your Main class should look like this:
package com.myplugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Main implements BundleActivator {
#Override
public void start(BundleContext bundleContext) throws Exception {
// Copy your start logic here
}
}
Then edit META-INF/MANIFEST.MF file and set for example
Bundle-Activator: com.myplugin.Main
This makes your Main class the activator of the plug-in: start() will be invoked at load.

Before/After Scenario not working in jbehave serenity BDD

Before/After Scenario not working in jbehave serenity BDD
serenity.version 1.2.3-rc.5
serenity.jbehave.version 1.21.0
Eg
public class UploadDocumentWhatStep {
#BeforeScenario
public void beforeEachScenario(){
System.out.println("in before");
}
#Given("Sample Given")
public void cleanUp() {
System.out.println("in given");
}
#When("Sample When")
public void action() {
System.out.println("in When");
}
#Then("Sample Then")
public void action() {
System.out.println("in then");
}
#AfterScenario
public void afterEachScenario(){
System.out.println("in After");
}
}
When i try to run this code the output is
Output:
in given
in When
in Then
This worked to me:
The JBehave API seems to have changed, it seems you now need to add the ScenarioType parameter:
#BeforeScenario(uponType = ScenarioType.ANY)
public void setTheStage() {
OnStage.setTheStage(new OnlineCast());
}
Source: https://github.com/serenity-bdd/serenity-jbehave/issues/117
JBehave determines Scenario by your .story file. Chances are you either did not define scenarios in your story file or there is a syntax error and it's being ignored. post your story file here.

Minecraft 1.9 modding block rendering error

I'm trying to render a block with a custom model in my 1.9 mod but it gives me a error at .getItemModelMesher
Code:
public class ModBlocks extends Blocks {
public static Block wooden_table;
public static void init() {
// Create Block
wooden_table = new Block(Material.wood).setUnlocalizedName("wooden_table").setCreativeTab(CreativeTabs.tabMisc);
// Register
GameRegistry.registerBlock(wooden_table, wooden_table.getUnlocalizedName().substring(5));
}
public static void registerRenders() {
registerRender(wooden_table);
}
public static void registerRender(Block block) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0,
new ModelResourceLocation(
Main.MODID + ":" + Item.getItemFromBlock(block).getUnlocalizedName().substring(5),
"inventory"));
}
}
Crash report:
---- Minecraft Crash Report ----
Description: Initializing game
java.lang.NullPointerException: Initializing game
at mcrafterzzfurnituremod.blocks.ModBlocks.registerRender(ModBlocks.java:29)
at mcrafterzzfurnituremod.blocks.ModBlocks.registerRenders(ModBlocks.java:25)
Please help I can't find any solution for this problem. If you need more code then just ask.
Minecraft.getMinecraft().getRenderItem()
that part only exists in the INIT phase, and not the PreInit phase. there it's still null.
Register variants in preinit,
then register meshes in init
besure to call this via your clientproxy and not the commonproxy
ps, read the tutorial on http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/blockstates-and-metadata/ and download the example zip to understand where goes where normally

voce - Simple Java code not working

I recently installed Voce and am using it in my Java application. In Eclipse, I added the JAR files in voce-0.9.1/voce-0.9.1/lib to the libraries in my Java Build Path. From the documentation, I figured that this code should work:
import voce.SpeechSynthesizer;
public class Test
{
public static void main(String[] args)
{
// System.out.println("Speaking");
SpeechSynthesizer speaker = new SpeechSynthesizer("speaker");
speaker.synthesize("hello");
// System.out.println("Spoken");
speaker.destroy();
}
}
When I uncomment the output statements, the program outputs "Speaking", then almost immediately outputs "Spoken" without having made a sound. My volume is turned up. Does synthesize() speak the string or have I forgotten some initialization? And can you give me some code that should work?
Answer
Here is the code that worked (I used the static methods in SpeechInterface instead of a SpeechSynthesizer object):
public class Test
{
public static void main(String[] args)
{
voce.SpeechInterface.init("../../../lib", true, false, "", "");
System.out.println("Speaking");
voce.SpeechInterface.synthesize("hello");
System.out.println("Spoken");
try { Thread.sleep(1000); } catch(Exception ex) {}
voce.SpeechInterface.destroy();
}
}

Categories

Resources