I need to import the project as mentioned in this link.
I am not using git, hence I have downloaded the project zip folder and extracted. Could you please let me know how to import this LibGdx sample project ?
This project is about 3 years ago, perhaps the APIs libgdx not be supported 100% by the cycle of listener aplication, or the project will not be prepared to be exported, and is a simple guide. I do not know the truth but looking at the repo what comes to mind is the following.
I think the easiest wayIt would create a new project, libgdx.
Copy, android asset data folder in to the new project android asset, and the Main folder, extract all files and copy to the core of the new project. change name package com.matsemann.libgdxloadingscreen; for you packege name and change other posible error in the files.
Take the class SomeCoolGame in "SomeCoolGame.java":
package com.matsemann.libgdxloadingscreen;
//
public class SomeCoolGame extends Game {
/**
* Holds all our assets
*/
public AssetManager manager = new AssetManager();
#Override
public void create() {
setScreen(new LoadingScreen(this));
}
}
as an entry point and adapt more or less something, eh not test but it's just so you can see the idea
package your.name.package;
//
public class MyGdxGame extends ApplicationAdapter {
/**
* Holds all our assets
*/
public AssetManager manager = new AssetManager();
#Override
public void create() {
setScreen(new LoadingScreen(this));
}
}
and work starting from there.
Related
IntelliJ does not find a main class in my Java application project. The project was cloned from a git repository so had no run configuration. I go to Edit Configurations, add a new Application template, go to Main class: and it says "No matches found in project".
So, manually searching through the hierarchy I find the .java file that contains the main function but it will not accept it as the main class. I've pasted the file below to prove that it has the correct main function.
public class AdvanceWarsGameHandler implements IGame
{
private Image mImage;
private String mTitle;
public AdvanceWarsGameHandler()
{
mTitle = "Advance Wars Game";
mImage = new Image("/OffBrandCerealOopsAllCarries2-01.png");
}
//Game logic unrelated to graphics goes here
#Override
public void update(Game game, float deltaTime)
{
}
//Update, but for graphics
#Override
public void render(Game game, Renderer renderer)
{
renderer.drawImage(mImage, game.getInput().getMouseX(), game.getInput().getMouseY());
}
public static void main(final String args[])
{
//Creating and starting an instance of AdvanceWarsGameHandler
AdvanceWarsGameHandler advancewars = new AdvanceWarsGameHandler();
Game myGame = new Game(advancewars);
myGame.start();
}
public String getTitle()
{
return mTitle;
}
}
So the question is, why is the IntelliJ project not recognizing the main function in this file, or what is IntelliJ looking for as the "Main class" of an application?
Okay, hopefully this answer will help others who are unfamiliar with IntelliJ IDEA.
The solution came in two parts
Part 1: Missing compilation directory.
Since I did not create the project from new and instead I cloned a Git repository, there was no default compilation directory set up.
To access this in IntelliJ IDEA go to File -> Project Structure -> Project and set the "Project compiler output" so the project can actually compile.
Part 2: Setting up the modules
The original project was created in Eclipse which has packages. In order to get those packages to work in IntelliJ, I had to go to the Modules tab of the Project Structure menu and set my src and res folders as Source and Resource Folders. This allowed IntelliJ to find the main() function in my class and the program ran as expected.
This solved my problem though if any of you IntelliJ users out there can see anything bad about what I did to get it working, please comment.
Edited to restart question from scratch due to complaints. I am a newbie to this format and to intellij so please excuse...
I am building a project in intellij for class. This project imports jnetcap and uses it to process a captured pcap file. My issue is I have two class files I am trying to integrate. NetTraffic which is the user interface class, and ProcessPacket that actually reads in the packet and does the work.
I have tried to make a project and import ProcessPacket into NetPacket but have been unsuccessful so far. I am sure I am missing something simple in this process but I just can not find anything showing the proper way to do this.
I have gotten it working by making a package under the src directory and adding both files to that package. This doesn't require an import from the NetPacket class and seems to work but my worry is that I need to be able to run this from a linux command line. I have been working all semester so far with everything in one source file so it hasn't been an issue until now. I don't remember using packages in the past under eclipse to do this.
Can someone offer a step by step process on how to properly add these source files to my project so that I am able to import ProcessPacket into NetTraffic or will leaving like this in a package work fine?
The files in question reside in package named nettraffic in src directory.
NetTraffic.java
package nettraffic;
public class NetTraffic {
public static ProcessPacket pp;
public static void main (String args[]) {
pp = new ProcessPacket();
pp.PrintOut();
}
}
ProcessPacket.java
package nettraffic;
import org.jnetpcap.*;
public class ProcessPacket {
public ProcessPacket() {
}
public void PrintOut() {
System.out.println("Test");
}
}
Note there is no real functionality in these at this time. Just trying to get the class import syntax correct before continuing. Again while this seems to work as a package I want to have it done without using a package and importing ProcessPacket.java into NetTraffic.java.
public class NetTraffic {
ProcessPacket pp = new ProcessPacket();
pp.PrintOut();
}
You're calling the PrintOut() method outside of any constructor or method or similar block (static or non-static initializer blocks...), and this isn't legal. Put it in a constructor or method.
public class NetTraffic {
public NetTraffic() {
ProcessPacket pp = new ProcessPacket();
pp.PrintOut();
}
}
I already have a Java application with Swing GUI which reads a bunch of XML files and makes some graphs based on the information found in those XML files.
Now I was asked to turn that application into an Eclipse Plugin so the application can be launched from inside the Eclipse IDE. On top of that I have to make my application to sometimes open an XML file which contains the data that the user clicks.
Now, after a fast walk through a tutorial about how to make an Eclipse Plugin, it does not seem that I will be able to use Swing components inside a Plugin Project. I have seen that there are other tools and frameworks for making GUI for a plugin.
I need a suggestion for how can I turn my Swing application into an Eclipse plugin, the easiest possible. Even with some frameworks for Swing I had a hard time to make a treelayout graph. I imagine that should be even harder to implement into Eclipse plugin if Swing components do not work over there.
Here it is how my application looks like right now, based on Swing components:
If you don't want to rewrite the whole application, you may want to check possibilities of using SWT_AWT bridge, which allows to integrate Swing applications into SWT world. It is pretty easy, but you may want to check some articles as well.
I used it to integrate some Swing-based print preview functionality into existing Eclipse-RCP application. Worked well, though it still has its own underwater rocks.
You can use Swing components inside a Eclipse plugin.
For demonstaration I took the Swing components from https://code.google.com/p/treelayout/ and put them into an Eclipse view:
The important file looks like this:
package createaview.views;
import org.abego.treelayout.demo.swing.SwingDemo;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
public class TreeView extends ViewPart {
public static final String ID = "createaview.views.SampleView";
private TableViewer viewer;
class ViewContentProvider implements IStructuredContentProvider {
public void inputChanged(Viewer v, Object oldInput, Object newInput) {}
public void dispose() {}
public Object[] getElements(Object parent) {
return new String[] {"One", "Two", "Three"};
}
}
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
public String getColumnText(Object obj, int index) {
return getText(obj);
}
public Image getColumnImage(Object obj, int index) {
return getImage(obj);
}
public Image getImage(Object obj) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
}
}
class NameSorter extends ViewerSorter {
}
public TreeView() {}
public void createPartControl(Composite parent) {
Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
java.awt.Frame frame = SWT_AWT.new_Frame(composite);
frame.add(SwingDemo.getPanel());
}
public void setFocus() {
viewer.getControl().setFocus();
}
}
and if you pass me an email address I'll bundle up the demo project I did and send them to you (actually, it should probably be that if this is looking like the right answer, I'll put the projects in a zip file somewhere around here for the community to have a look at)
I'm creating a Java library for using in other Java projects. The projects use Repast Symphony and my library does so too (so i'm afraid this error is being caused by some conflict). Everything builds fine, but when I run a the Repast simulation, it throws java.lang.NoClassDefFoundError: repast/simphony/context/Context
I tried exporting my library as a jar, importing the project directly and adding the library to my project's classpath, to no avail. What can I be doing wrong?
This Context class is being used in both my library and my projects. The following is a snippet of it use in two classes:
// MyContextBulder.java
// This file is in my project
// This class is called by Repast first
import repast.simphony.context.Context;
import repast.simphony.dataLoader.ContextBuilder;
import mylibrary.core.DF;
import mylibrary.core.DF.MyContext;
public class MyContextBuilder implements ContextBuilder<Object> {
#Override
public Context<Object> build(Context<Object> context) {
context.setId("test");
DF.setContext((MyContext) context);
// Create agent
new MyAgent();
// Add the agent to the Repast context.
// context.add(t);
return context;
}
}
// DF.java
// This file is in my library
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import org.apache.commons.collections15.Predicate;
import repast.simphony.context.Context;
import repast.simphony.context.ContextListener;
import repast.simphony.space.projection.Projection;
import repast.simphony.util.collections.IndexedIterable;
import repast.simphony.valueLayer.ValueLayer;
import mylibrary.Agent;
/**
* This static class provides the Directory Facilitator Service
* and is used to send messages to agents
* and to keep a directory of all agents in the application.
* Agents use the static method send(ACLMessage) to send a message
* to one or more agents. The ACLMessage object contains
* the receiver agent and the sender (so the receiver can reply back).
*
* This class needs to be setup initially before registering new agents.
* To do that, simply call setContext(...);
* #author joaolopes
*
*/
public class DF {
private static int lastAID = 0; // Just to help generate new identifiers
private static HashMap<Integer, Agent> agents; // Contains all agents
/**
* The Repast context that contains all
* scheduled Repast objects.
*/
private static MyContext context = null;
/**
* Registers the agent in the directory and returns its
* AID (freshly generated for it). If the agent is already
* registered, returns its current AID.
* #param agent The agent to be registered
* #return The AID generated for the agent.
*/
public static int registerAgent(Agent agent) {
// If this agent is already in the hashMap,
// just return its key.
if (getAgents().containsValue(agent)) {
return agent.getAID();
}
// Quick way to find a new ID for this agent
// that is not in use at the moment.
while (getAgents().containsKey(lastAID)) {
lastAID++;
}
// The agent must know their own ID.
agent.setAID(lastAID);
agents.put(lastAID, agent);
System.err.println(context.toString());
context.add(agent);
return lastAID;
}
public static void setContext(MyContext c){
context = c;
}
}
Editing to add relevant info from the comments:
I don't import the repast JAR directly in my projects as I do in my library. Repast Symphony is installed in Eclipse as a plugin, so I created "Repast Projects" that include all Repast libraries. Therefore, I'm unable to remove the specific JAR that is causing the possible conflict of classes.
Exactly as you said. This error should be the conflict between the same classes in a jar. If you are using an IDE try to clean the build and rebuild again.
And also I would suggest you to use only one symphony library jar. Multiple class definitions always leads to ambiguity for the JVM class loader.
Try not to use symphony jar in the importing project since you already have it in your exported jar. After importing your lib, there should no errors.
Try this and let me know how it goes.
I suggest that you use an build tool. Something like Maven. Then maven with the right plugin will fix this problem for you. All you need to do, is to tell Maven that you need a particular jar file. Then a magic will occur, and you will have a well working jar-file to distribute
java.lang.NoClassDefFoundError is thrown when the JVM tries to run the application. Typical cases is when you got one jar-file as "interface". Then you got other jar-file that implement that interface.
So what you need to do, is that have the Repast jar inside your jars classpath. So that your program can find the right class you want to use.
I have managed to add a custom class to a user's project(in Blue J). I am developing inside eclipse.
I was just wondering if anyone could help with the theory of what to do after adding the java file to the project directory and then compiling it.
I have a class file and a java file inside the user's project but I assume that I need to add it to the class loader being used in BlueJ.
I have tried a number of ways but keeping getting ClassNotFoundException
My best attempt so far is:
/**
* #param cLoader the bluej class loader inside eclipse
* #param packageName the name of the package the bluej project belongs to
*/
public void addURL(ClassLoder cLoader, String packageName)
{
try
{
ClassLoader classLoader = cLoader;
classLoader.loadClass(packageName);
}
catch(ClassNotFoundException e)
{
//do something
}
}