so i was following a tutorial on youtube on how to make a minecraft pvp client and when i followed the steps to make a test mod in minecraft that tests the input/to show something in console when you press "b" for example but when i typed in modmanager.testMod.toggle(); eclipse said the method toggle() is undefined for type TestMod.
i changed it to .OnToggle() but it didn't work so i pressed create method "toggle()" and that didn't work either. by the way it created public void toggle() { in TestMod.java
Related
I have been trying to call a Java method in unity. Not working for me, even the simplest example from the docs
using System.Collections;
using UnityEngine;
public class ExampleClass : MonoBehaviour {
void Start () {
AndroidJavaObject jo = new AndroidJavaObject ("java.lang.String", "some string");
int hash = jo.Call<int> ("hashCode");
Debug.Log ("hash=" + hash);
}
}
Unity console prints hash=0, which is not the hash code for provided String. Even if I change and use java.lang.StringInvalidClass as class name, unity still reports same result to the console without notifying errors. I can even try to call toString, toStringa, toInvalid2 and they always return empty string without showing errors.
This is a brand new 2d project with only script displayed above, attached to camara object. I am using Ubuntu, Unity 2019.4 and project platform is Android.
Thanks for the assistance.
Answering myself after some time working with unity.
All examples in the web and unity documentation doesn't mention it, which is weird since it is something simple to mention and about confusions: code needs to run as an android application. Editor or even unity remote does not work, in order to use AndroidJavaObject and related classes, your code needs to run as an android application installed in the phone.
I have an Android Studio project, generated from a Unity3d Project.
I wanted to run my project on a Google Glass so I followed this tutorial (http://forum.unity3d.com/threads/how-to-build-for-google-glass.219558/).
Everything works fine so far, but I can't close the app via swipe down, even though I added this to the UnityPlayerActivity.java:
#Override public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){ finish(); }
return true;
}
Again, everything else works just fine.
1st UPDATE:
I tried the application on a tablet - like on the Glass, "Back"-button does not work.
Then I implemented this in Unity:
if(Input.GetKeyDown(KeyCode.Escape)){
Application.Quit();
}
Now it works on the tablet, but the Glass-situation did not change.
2nd UPDATE:
This also didn't work: this.finishAffinity();
3rd UPDATE:
I tried to close my Unity Application using this Coroutine in the Start()-Method:
IEnumerator waitAndExit(int sec)
{
yield return new WaitForSeconds(sec);
Application.Quit();
}
This successfully shuts down my application, so the problem appears to be this:
Unity does not recognize swiping down on Google Glass as a keyEvent in Input and the UnityPlayer object seems to get ALL input from android.
How can I stop that?I wan't to handle touchpad events with java, but my original idea - overriding onKeyDown - did not work.
4th Update:
I tried to recognize a gesture like in this answer and added this to my onCreate():
mUnityPlayer.setFocusable(false);
//mUnityPlayer.requestFocus();
Unfortunately it did not help.
This is not really a solution, but rather a work-around:
Using contextual voice commands works fine, even with the UnityPlayer-object blocking touchpad input.
I now close my app via "OK glass - quit".
If anybody figures out how to solve it properly - I'll test, verify and accept your answer.
I am trying to launch an external application for testing using UISpec4J.
Here are the questions and their answers I referred so far:
How to automate a swing java web start application which runs clicking a link into a web application, which is automated with Selenium WebDriver?
Getting all windows using UISpec4J
UISpec4J Capturing modal dialog, before the trigger finish
my.exe referred below is a Java application wrapped in exe using some tool. Internally it uses the jars and is Java GUI application.
This executable launches a splash screen first, then a dialog to choose where you want to connect to and after that main window is shown. Unless I can automate where I can connect to I won't get main window.
Based on these questions I have come up with following code fragments:
this.setAdapter(new UISpecAdapter() {
#Override
public Window getMainWindow() {
return WindowInterceptor.run(new Trigger() {
#Override
public void run() throws Exception {
// running jnlp by netx launcher
Runtime.getRuntime().exec("C:\\my.exe");
Thread.sleep(10000);
}
});
}
});
In the approach above I simple get "No window was shown" error.
this.setAdapter(new UISpecAdapter() {
#Override
public Window getMainWindow() {
final Window[] result = new Window[1];
WindowInterceptor
.init(new Trigger() {
#Override
public void run() throws Exception {
Runtime.getRuntime().exec("C:\\my.exe");
//Thread.sleep(10000);
}
})
//.processTransientWindow()
.process(new WindowHandler() {
public Trigger process(Window window) throws Exception {
result[0] = window;
return Trigger.DO_NOTHING;
}
})
.run();
return result[0];
}
});
In the second approach above, I still get "No window shown" error AND control never reaches to overriden "process" method.
I referred to http://www.uispec4j.org/reports/apidocs/org/uispec4j/interception/WindowInterceptor.html and recommended approach is to use init to capture modal dialog is init\process sequence.
To capture non-modal it is recommended that we should use following:
Window window = WindowInterceptor.run(panel.getButton("open").triggerClick());
But I have NO idea where and how I am supposed to call it..
From the first question I referred, mentioned above, we should be able to do that because the answer to it mentions launching jnlp application which is external application.
I tried with jre 6 update 0 and I can at least run test. In java update 37, from the third question I referred above, I get abstract method not implemented error.
What am I doing wrong? Any idea?
I am using latest UISpec4J package - version 2.4.
Thanks in advance,
-Neel.
I'm very new to UISpec4J but I'm guessing it needs to run in the same JVM in order to intercept and interact with the GUI components. When you start the exe file with exec, it will create a new process and a new, separate JVM. That'll not work, if I understand UISpec4J correctly.
Regarding the non-modal example, the documentation says "You would retrieve the window from within the test...", so in a setup method or in a test should work.
I am using Eclipse Luna and i am trying to run a simple text program but Eclipse gives the error:
Error: Could not find or load main class Main
I have no idea what's going on. I haven't found anything useful on Stack Overflow or Google. Here is my code:
public class Main {
public static void main(String[] args) {
System.out.println("This is a String");
}
}
Thank you.
Your code looking fine !
Do following steps to run your class
Select your project, go to Project section in menu bar then click clean.
In tool section click on enter code here Build Automatically.
Select your class right click on it and then select run.
In the menu Run, select Run Configurations....
In the dialog box that opens, on the left side, you are supposed to have an entry Java Application, and under it, there should be your class (and maybe other classes you worked on before). It may be named Main or Main__ here.
Select it. If it was erroneously named Main__, change that to Main in the Name: field.
Now look at the entry for Main Class. In the text field, it should say Main. If it says Main__ or anything else, change that to Main.
Apply and Run.
we have the following problem:
In our Eclipse RCP 4 application there are multiple parts and the parts are closable. When the user is closing a part there should be a custom pop-up (depending on some internal part state) which is asking the user if he really wants to close the part or not.
It seems to be not that easy to implement in Eclipse RCP 4 or we have just totally overseen something.
I'll just give you a short brieifing about the things we tried:
Use dirtable with a #persist method in the part. Though the problem is, we don't want this standard eclipse save dialog. So is there a way to override this?
public int promptToSaveOnClose(): This seemed to be promising but not for Eclipse 4 or is there a way to integrate it that way? Compare: http://e-rcp.blogspot.de/2007/09/prevent-that-rcp-editor-is-closed.html
Our last try was to integrate a custom part listener, simple example shown in the following:
partService.addPartListener(new IPartListener() {
public void partVisible(MPart part) {
}
public void partHidden(MPart part) {
partService.showPart(part, PartState.ACTIVATE);
}
public void partDeactivated(MPart part) {
}
public void partBroughtToTop(MPart part) {
}
public void partActivated(MPart part) {
}
});
The problem with this was we are running into a continuous loop. Something similar is posted over here in the last comment: Detect tab close in Eclipse editor
So I could write some more about this problem, but I think that's enough for the moment. If you need some more input just give me a hint.
Thanks for helping.
The save prompt is generated by the ISaveHandler registered in the context of the MWindow containing the MPart. You can write your own ISaveHandler and set it in the window context to replace the default.
You might also want to look at the IWindowCloseHandler also in the window context.
Thanks greg, this has helped and I was able to achieve changing the pop-up when the user closes a part. Here's a short description of what I've done:
Use the MDirtyable for marking the part as dirty whenever it's needed.
Create a custom save handler which implements ISaveHandler (when a part got closed the save method is called). Add the additional logic to this handler (e.g. a custom message dialog)
Register this handler at application start-up (I just chose a method which is called at the start-up):
#Inject
private MWindow window;
...
ISaveHandler saveHandler = new CustomSaveHandler(shell);
window.getContext().set(ISaveHandler.class, saveHandler);
Note that the registration via a model processor was sadly not that easy because the model processor is called too early. (Take a look at: http://www.eclipse.org/forums/index.php/t/369989/)
The IWindowCloseHandler is just needed when the complete window is closed, though this was not an requirement for us :).