The import org.opencv.imgcodecs.Imgcodecs cannot be resolved - java

I installed OpenCV (opencv-3.0.0-alpha) and it works properly but I can't use that import:
import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
public class Main {
public static void main(String[] args) {
// System.loadLibrary("opencv_java244");
// Mat m = Highgui.imread("C:/Users/raj/Desktop/sa1.png",
// Highgui.CV_LOAD_IMAGE_COLOR);
// new LoadImage("C:/Users/raj/Desktop/dst1.jpg", m);
}
}
I get this error
The import org.opencv.imgcodecs.Imgcodecs cannot be resolved
How can I solve this?

OpenCV 3.0.0 is using the import:
import org.opencv.imgcodecs.Imgcodecs;
However the library you are using (OpenCV 2.4.1) is using different import for the same functionalites:
import org.opencv.highgui.Highgui;
https://fossies.org/diffs/opencv/2.4.11_vs_3.0.0-rc1/modules/java/android_test/src/org/opencv/test/highgui/HighguiTest.java-diff.html
Basically you are trying to import something that doesn't exist in the version you are using.
Now you can either use Highgui or get the jar for OpenCV 3.1.x

Related

Compile Error: Package sqlj.runtime does not exist

I am trying to do a homework assignment in a database course that requires me to use sqlj. It is supposed to make a connection to a SQL database running on my computer. When copying and pasting the example code into Netbeans I get a compile error:
package sqlj.runtime does not exist: import sqlj.runtime.*;
import java.sql.*;
import java.io.*;
import sqlj.runtime.*;
import sqlj.runtime.ref.*;
import oracle.sqlj.runtime.*;
public class A10Q1 {
public static void main(String[] args) {
DefaultContext cntxt = oracle.getConnection("url", "user", "pswd", true);
}
}
I changed the inputs on the getConnection function.

Unable to import a Scala object into the Java project

I created a Scala object:
package myapp.data
import java.io.File
import myapp.models.NodeViewModel
import com.thoughtworks.xstream.XStream
import com.thoughtworks.xstream.io.xml.DomDriver
object ForumSerializer {
def openFile(file : File) : NodeViewModel = {
// doing something
}
def saveToFile(model : NodeViewModel) : Unit = {
// doing something
}
}
Then I tried to import it in another Java file
import myapp.ForumSerializer;
The error I get is:
Import myapp.ForumSerializer cannot be resolved.
What am I doing wrong?
Import it as ForumSerializer$.
Scala adds a $, so the compiler doesn't get confused with the class, when you have both an object and a class of the same name. You can then access the singleton object using the generated MODULE$.

libgdx not initialized yet

I have been coding my libgdx application (for desktop only) for a while and after deciding to cleanup the code part by part iv'e gotten into a problem i cant seem to solve myself..
exception:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131)
Caused by: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape(Native Method)
at com.badlogic.gdx.physics.box2d.PolygonShape.<init>(PolygonShape.java:29)
at com.mygdx.game.handler.BodyEditorLoader.<init>(BodyEditorLoader.java:41)
at com.mygdx.game.util.GameUtils.init(GameUtils.java:23)
at com.mygdx.game.DungeonLife.create(DungeonLife.java:168)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
after googling for a while i figured my error is as mentioned in this thread
as in
Another problem might be that you instantiate a SpriteBatch (or something else which internally uses a SpriteBatch) too early (looked a bit like this in the stacktrace).
but as the answer mentions
Instead, create such things in the create/show methods of your game.
I cant seem to understand when libgdx is initialized and ready for use, and where to place my GameUtils.init() method to assure libgdx is initialized
My code is as follows: (i have taken out e-relevant methods)
Application Class
package com.mygdx.game;
import box2dLight.RayHandler;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import com.mygdx.game.entity.MobEntity;
import com.mygdx.game.entity.PhysicalEntity;
import com.mygdx.game.entity.Player;
import com.mygdx.game.entity.Weapon;
import com.mygdx.game.handler.*;
import com.mygdx.game.util.CollisionConstants;
import com.mygdx.game.util.GameUtils;
import com.mygdx.game.util.TileObjectUtil;
import com.mygdx.game.util.WorldConstants;
import com.mygdx.game.valtype.WeaponDefinition;
public class DungeonLife extends ApplicationAdapter implements WorldConstants {
OrthographicCamera camera;
float width , height;
Texture texture;
TextureRegion[] enttex;
//TEMP
MobEntity demo;
Player thePlayer;
PlayerInputProcessor playerInputProcessor;
ScreenUI ui;
int mapWidth , mapHeight;
//========================================
GameMap gameMap;
//========================================
#Override
public void create () {
texture = new Texture("maps/img/tileset_entity.png");
enttex = new TextureRegion[(int) ((texture.getWidth()*texture.getHeight()) / (BLOCK*BLOCK))];
enttex[0] = new TextureRegion(texture , 0 , 0 , (int)BLOCK , (int)BLOCK);
enttex[1] = new TextureRegion(texture , (int)BLOCK , 0 , (int)BLOCK , (int)BLOCK);
width = Gdx.graphics.getWidth()/5;
height = Gdx.graphics.getHeight()/5;
camera = new OrthographicCamera(width,height);
camera.position.set(width / 2, height / 2, 0);
camera.update();
GameUtils.init(); // <------this guy
//init();
} ...
GameUtils
package com.mygdx.game.util;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.World;
import com.mygdx.game.entity.PhysicalEntity;
import com.mygdx.game.handler.*;
import java.util.PriorityQueue;
public class GameUtils {
public static void init(){
weapon_bodyEditorLoader = new BodyEditorLoader(Gdx.files.internal("textures/weapons/dungeonlife_weapons.json"));
resourceManager = new ResourceManager();
resourceManager.addRes("friendlyhealth" , new Texture("textures/ui/friendlyhealth.png"));
resourceManager.addRes("enemyhealth" , new Texture("textures/ui/enemyhealth.png"));
tmxMapLoader = new TmxMapLoader();
gameContactListender = new GameContactListender();
}
//GLOBAL
public static BodyEditorLoader weapon_bodyEditorLoader;
public static GameContactListender gameContactListender;
public static ResourceManager resourceManager;
public static TmxMapLoader tmxMapLoader;
//CURRENTS ============================
public static GameMap CURRENT_GAMEMAP;
}
Desktop launcher (the usual)
package com.mygdx.game.desktop;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.mygdx.game.DungeonLife;
import com.mygdx.game.util.GameUtils;
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.useGL30 = false;
config.width=640;
config.height=360;
DungeonLife dungeonLife = new DungeonLife();
new LwjglApplication(dungeonLife, config);
}
}
Help is much appriciated! :D
As I've already wrote in the other linked answer, make sure that your project is correctly set up. Box2D is an extension and needs its own native libraries to be able to run.
It seems that it's a specific problem with the Box2D natives which are not loaded yet. They are not loaded automatically when LibGDX is initializing, but you have to trigger that yourself (see wiki).
The code you've posted looks correct, but before you can use anything Box2D related, you have to call Box2D.init(). Alternatively, creating a World object does the same, but isn't the nicest way to do it.

Java Network Simulator Getting Started

I am working on simulating a network topology with Java Network Simulator(JNS). I have followed the tutorial which is in documentation of JNS download. Following is the code of the example:
package simulator_;
import java.awt.peer.TextComponentPeer;
import java.io.IOException;
import jns.Simulator;
import jns.element.DuplexInterface;
import jns.element.DuplexLink;
import jns.element.Interface;
import jns.element.Link;
import jns.element.Node;
import jns.trace.Event;
import jns.trace.Trace;
import jns.util.IPAddr;
public class simu {
public static void main(String[] args) {
Simulator sim=Simulator.getInstance();
Node src=new Node("Source node");
Node router=new Node("Router");
Node dest=new Node("Destination node");
sim.attach(src);
sim.attach(router);
sim.attach(dest);
Interface src_iface=new DuplexInterface(new IPAddr(192,168,1,10));
src.attach(src_iface);
sim.attach(src_iface);
Interface dest_iface=new DuplexInterface(new IPAddr(128,116,11,20));
dest.attach(dest_iface);
sim.attach(dest_iface);
Interface route_iface192=new DuplexInterface(new IPAddr(192,168,1,1));
Interface route_iface128=new DuplexInterface(new IPAddr(128,116,11,1));
router.attach(route_iface192);
router.attach(route_iface128);
sim.attach(route_iface192);
sim.attach(route_iface128);
Link link_src_router=new DuplexLink(1000000,0.001);
Link link_router_dest=new DuplexLink(64000,0.1);
src_iface.attach(link_src_router,true);
route_iface192.attach(link_src_router,true);
sim.attach(link_src_router);
route_iface128.attach(link_router_dest,true);
dest_iface.attach(link_router_dest,true);
sim.attach(link_router_dest);
src.addDefaultRoute(src_iface);
dest.addDefaultRoute(dest_iface);
router.addRoute(new IPAddr(192,168,1,0),new IPAddr(255,255,255,0),
route_iface192);
router.addRoute(new IPAddr(128,116,11,0),new IPAddr(255,255,255,0),
route_iface128);
sim.run();
}
}
The problem I am facing is when I call sim.run(), the program throws me NullPointerException error. I am a newbie in JNS. Kindly guide if how can I successfully create a file foe javis to Simulate with the help of above code. I am using Eclipse IDE.
Thanks in advance.
try setting a trace instance
sim.setTrace(new JavisTrace("output.txt"));

passing argument to WordCram code

I have the following question: I am trying to execute the usConstitution wordcram example (code follows) and if provided as is the code executes in eclipse, the applet starts and the word cloud is created. (code follows)
import processing.core.*;
//import processing.xml.*;
import wordcram.*;
import wordcram.text.*;
import java.applet.*;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.MouseEvent;
import java.awt.event.KeyEvent;
import java.awt.event.FocusEvent;
import java.awt.Image;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class usConstitution extends PApplet {
/*
US Constitution text from http://www.usconstitution.net/const.txt
Liberation Serif font from RedHat: https://www.redhat.com/promo/fonts/
*/
WordCram wordCram;
public void setup() {
size(800, 600);
background(255);
colorMode(HSB);
initWordCram();
}
public void initWordCram() {
wordCram = new WordCram(this)
.fromTextFile("http://www.usconstitution.net/const.txt")
.withFont(createFont("https://www.redhat.com/promo/fonts/", 1))
.sizedByWeight(10, 90)
.withColors(color(0, 250, 200), color(30), color(170, 230, 200));
}
public void draw() {
if (wordCram.hasMore()) {
wordCram.drawNext();
}
}
public void mouseClicked() {
background(255);
initWordCram();
}
static public void main(String args[]) {
PApplet.main(new String[] { "--bgcolor=#ECE9D8", "usConstitution" });
}
}
My problem is the following:
I want to pass through main (which is the only static class) an argument so as to call the usConstitution.class from another class providing whichever valid filename I want in order to produce its word cloud. So how do I do that? I tried calling usConstitution.main providing some args but when I try to simply print the string I just passed to main (just to check if it is passed) I get nothing on the screen. So the question is How can I pass an argument to this code to customize .fromTextFile inside initWordCram ?
Thank you a lot!
from: https://wordcram.wordpress.com/2010/09/09/get-acquainted-with-wordcram/ :
Daniel Bernier says:
June 11, 2013 at 1:13 am
You can’t pass command-line args directly to WordCram, because it has no executable.
But you can make an executable wrapper (base it on the IDE examples that come with WordCram), and it can read command-line args & pass them to WordCram as needed.
FYI, it’ll still pop up an Applet somewhere – AFAIK, you can’t really run Processing “headless.” But that’s usually only a concern if you’re trying to run on a server.

Categories