Odoo mobile sync does not work - java

I downloaded the odoo framework from the github, I installed it and locally every thing is working just fine, But it does not sync with the server no records came from the server and none go, It just work locally
I have seen the issues part in the github, but i does't give so much help
Is there any one knows what exaclly the problem?? Or any one have working copy of the framework??

I had the same problem but syncing worked fine after commenting out the some lines out of the file ContentResolver.java: search for lines 2326, 2327, 2328
public static void setMasterSyncAutomatically(boolean sync) {
setMasterSyncAutomaticallyAsUser(sync, UserHandle.myUserId());
}
change them to:
// public static void setMasterSyncAutomatically(boolean sync) {
// setMasterSyncAutomaticallyAsUser(sync, UserHandle.myUserId());
// }
I know this is not the correct way to do it, because you seem to override the authorisation check, but for me, for now, and for testing purposes it works.
(hope it helps, please don't shoot me)

Related

Player*First*JoinEvent how should i do that?

so i tried to make a simple PlayerJoinEvent (AKA. PlayerFirstJoinEvent) for my server. Is there a way to do that? I want to run my code when player joins the server first time. I have tried multiple options like using if(player.hasPlayedBefore()) but it doesent want to work! So, do you have an idea how to fix it or do it with a different method? Thanks to everyone for help!
You haven't probably deleted player data! If new player joins, new player data are created, only then does Spigot know, that the player is new to the server!
To do so:
Shutdown your server
Go to server-folder/world/playerdata/*player-uuid*.dat
Delete player-uuid.dat
Start the server
Warning: This deletes player inventory!
If your server is in offline mode, and you don`t know what your UUID is, use this online tool.
If your server is in online mode, and you don't know your UUID, use namemc
Code to test the event:
#EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if(!event.getPlayer().hasPlayedBefore()) {
event.getPlayer().sendMessage("Hi!");
}
}
Don't forget to register this event in your main class!
So i solved it and Thanks to everyone for help there wasnt any problem with hasPlayedBefore().

How to let run only one instance of application at a time?

I am working on a GUI application that uses JavaFX(not fxml) and exported as a JAR. For slow machine, impatient user click more than once on JAR, and multiple instances of application started.
I'm looking for a solution to let only one instance can be run at a time on a system and if the user clicks again while the application is running nothing happens. I think it's called singleton but don't know how to implement it.
You could try JUnique. It's an open source library doing exactly what you ask for. Import junique-1.0.4.jar to your project as a library. It's just 10kb file.
It's manual neatly describes how to implement it on a project. For a JavaFX application, implementation would look something like this:
Make sure to import these classes to your main
import it.sauronsoftware.junique.AlreadyLockedException;
import it.sauronsoftware.junique.JUnique;
public static void main(String[] args) {
String appId = "myapplicationid";
boolean alreadyRunning;
try {
JUnique.acquireLock(appId);
alreadyRunning = false;
} catch (AlreadyLockedException e) {
alreadyRunning = true;
}
if (!alreadyRunning) {
launch(args); // <-- This the your default JavaFX start sequence
}else{ //This else is optional. Just to free up memory if you're calling the program from a terminal.
System.exit(1);
}
}
One easy solution that I've used is, when you start the application, it creates a file (I named it .lock but you can call it whatever you want), unless the file already exists, in which case the application terminates its execution instead of creating the file.
You will need to bind your application with a resource. It can be a file, port etc.
You can change the code on startup to check if the file is locked. The below code will give you some idea
FileOutputStream foStream = new FileOutputStream("/tmp/testfile.txt");
FileChannel channel = fileOutputStream.getChannel();
FileLock lock = channel.lock();
If you'd properly package your JavaFX code as a real application instead of just throwing it into a jar, you might get that functionality for free and without all these hacks. If I package my JavaFX code on my Mac with the jpackage tool, the result will be a full featured macOS application. That means that when I double-click its icon somewhere several times, only one instance of the application will be started. This is the default behaviour on Macs and properly packaged JavaFX applications just stick to that rule too. I can't say however what the behaviour on Windows or Linux is because I currently don't have such a box running. Maybe someone who knows can add this as a comment.

Modifying react-native files

i changed a BaseViewManager.java file inside of react-native to make resource-id available thru react-native. the thing is that no matter what i do, nothing takes effect, even if i put typos in the .java files. my colleague told me it's probably because the .java is not being built.
so how to build the react-native .java files??
i tried npm start of course but nothing took any effect.
and this is the code that i want to change
#ReactProp(name = PROP_TEST_ID)
public void setTestId(T view, String testId) {
view.setTag(R.id.react_test_id, testId);
// temporarily set the tag and keyed tags to avoid end to end test regressions
view.setTag(testId);
}
#ReactProp(name = PROP_NATIVE_ID)
public void setNativeId(T view, String nativeId) {
view.setTag(R.id.view_tag_native_id, nativeId);
ReactFindViewUtil.notifyViewRendered(view);
}
You have to build React Native from source. Here is tutorial for that: https://reactnative.dev/contributing/how-to-build-from-source I tried it and it works :)

getResourceAsStream(); always NULL (Netbeans)

I've spent almost 2 days in trying to load files from inside of my netbeans project, but it always gives NullPointException.
currently my directory looks like:
JavaFXApplication:
src
--Manifest (contains Manifest.java)
--images (inside Manifest package aka Manifest.images)
--server.jpg (inside images package)
I'm trying to load the server.jpg from images package, but it always return NULL.
Here is the snippet of my code:
try {
rect.setFill(new ImagePattern(new Image(Manifest.class.getResourceAsStream("images\\server.jpg"))));
} catch (NullPointerException e) {
System.out.println(Manifest.class.getResourceAsStream("server.jpg"));
}
Exactly 2 days before, I saw this code from a YouTube Tutorial, and it doesn't worked. Try many of those solutions from here, but nothing yield for me.And suddenly it worked. Next day, tried to run the same code, and again same NULL error.
Can you guys please help me. I'm totally new to JavaFX. Don't have much experience with it.
Use getClass().getClassLoader().getResourceAsStream(""). When you do Manifest.class.getResourceAsStream("images\\server.jpg"), it will try to load the file relative to where the Manifest.class is present.

Java equivalent of #ifdef that allows non-compilable code

Is it possible in Java to do a sort of #ifdef thing, like in C/C++?
Example:
class Test
{
public static final boolean ANDROID = false;
public Test()
{
if (ANDROID)
{
// do stuff that won't compile if not on android
}
else
{
// do stuff that should be only done on desktop
}
}
}
Note that even if ANDROID is false, as in the example, it will still try to compile the code inside of the if, even though it won't (and shouldn't) compile.
I'm looking for a way to do conditional compilation -- the compiler shouldn't even look at the if if ANDROID is false.
The context of my question is that I have a Processing application in Eclipse. I'm using both normal Processing and Processing for Android in two separate projects, but I want to be able to move the source code of the projects between one another without having compiler errors. For example, I want to be able to have source code files that I can move from the Android project to the desktop project and only have to change a couple of things -- for example, changing ANDROID = true to ANDROID = false.
I really need it to be conditional compilation because when I copy the source code from the Android project to the desktop project, the desktop libraries obviously won't include Android libraries, and then the source code won't even compile.
EDIT: So now that I know that there is no preprocessor in Java, my question is: is there any other way to have this functionality in my projects (being able to copy source code from one to the other with only very minor changes) without having to manually [un]comment specific pieces of code and having to remember where those are?
EDIT 2: This is not a duplicate of the other question because my question includes code that may have compiler errors in it, whereas the question that this was closed as a duplicate of does not. (That other question concerns only code that would compile fine even without #ifdefs.) To explain, the most highly rated (and accepted) answer for the other question talks about code that is compiled, but is simply not emitted in the bytecode. However, my question concerns code that would not even compile originally.
As others have said, the answer to your actual question is no.
However, you might approach your problem by isolating the Android or desktop code. You could do this by having three separate projects in eclipse:
Core: This is the "shared" code that exists between both versions.
Android: This contains only the code that runs on Android.
Desktop: This contains only the code that runs on desktop.
Both your Android and Desktop projects would contain the Core project on their classpaths. In eclipse, you'd do this by going to your Java Build Path, then clicking the Projects tab, then adding the Core project to the "Required projects" list.
Then you'd set your code up so your Android and Desktop projects are what you actually deploy, and your Core project contains the code shared between them. Here's a simple example. Let's say we have an example class that looks like this:
public class Adder{
public void addAndPrint(int x, int y){
//code that will work on both Android and desktop
int sum = x+y;
if (ANDROID){
//code that will only work on Android
Log.v("example", "Sum:" + sum);
}
else{
//code that will only work on desktop
System.out.println("Sum: " + sum)
}
}
}
You could get around this by refactoring your code to isolate the "core" code that will work on both desktop and Android. Something like this:
//example core class
public class CoreAdder{
Printer printer;
public CoreAdder(Printer printer){
this.printer = printer;
}
public void addAndPrint(int x, int y){
int sum = x+y;
printer.print("Sum: " + sum);
}
}
//example core interface. We might print differently on
//Android and Desktop, so implement this interface in each.
public interface Printer{
public void print(String printMe);
}
Then, you'd isolate the code that will only work on Desktop:
//on desktop, use System.out.println()
public class DesktopPrinter implements Printer{
public void print(String printMe){
System.out.println(printMe);
}
}
//on desktop, entry point is main()
public class DesktopMain{
public static void main(String... args){
DesktopPrinter printer = new DesktopPrinter();
CoreAdder adder = new CoreAdder(printer);
adder.addAndPrint(1, 2);
}
}
And the code that will only work on Android:
//on Android, use a logger
public class AndroidPrinter implements Printer{
public void print(String printMe){
Log.v("example", "index=" + i);
}
}
//on Android, entry point is Activity
public class AndroidActivity extends Activity{
public void onCreate(Bundle savedInstanceState) {
AndroidPrinter printer = new AndroidPrinter ();
CoreAdder adder = new CoreAdder(printer);
adder.addAndPrint(1, 2);
}
}
Note that this is just an example, and I know that both System.out.println() and Log.v() could work on either platform. But the idea is the same: split your project up into multiple projects, and use interfaces to abstract away the behavior that changes between platforms.
As Java does not natively include a preprocessor, it would be incumbent upon you to manually execute one before compiling. The c preprocessor is m4, which you can run yourself.
There are no-preprocessors in java like C,C++ etc. All you can do is comment out the code.
Use #ifdef and friends as in C and run the Java sources through the C pre-processor before compiling them.
For gcc the pre-processor is called cpp, for VC it's cl.exe using the option /P.
No, there is no such thing as a preprocessor in Java that can hide chunks of code to the JVM.
EDIT:
While you could of course run any program against your code base to preprocess it, think about if you really want this. The Android code will diverge more from the other Java code in time and your code will be littered with those #ifdef-like statements. Your IDE will also still see them and give you errors in both areas of code. In this case it's much easier to just make two projects out of it or, and that's my advice, create a platform independent library which you include in both projects and includes the functionality you need.
By defining productFlavors in build you can use folders that will be compiled when specific flavor is chosen thus you can make code in same codebase available conditionally at compile time.

Categories

Resources