I am new to java though I have some experience with R.
I have taken part of a java course and have read a book or two as well as the API guides published by interactive brokers. This API is higher level than anything I have worked with before, obviously.
The very first thing I want to do is simply connect to the software. I have been able to do this with the test GUI that Interactive Brokers provides. However, when writing my own script, I am getting an error: Uncompilable source code - Erroneous sym type. I have imported the javaclient/com directory into my new project.
The line that is causing the error is econnect(port=7496, clientid=0);
Reading the documentation, this should work, but obviously does not.
Below is the full code. All of the import calls were copied from a sample file that IB provided. onHowToDetermineStock() is copied from another part of the documentation. Before I can do anything, I obviously need to to connect.
Any ideas?
Thank you.
package ibapp;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.util.ArrayList;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import com.ib.controller.ApiConnection.ILogger;
import com.ib.controller.ApiController;
import com.ib.controller.ApiController.IBulletinHandler;
import com.ib.controller.ApiController.IConnectionHandler;
import com.ib.controller.ApiController.ITimeHandler;
import com.ib.controller.Formats;
import com.ib.controller.Types.NewsType;
import com.ib.client.EClientSocket;
/**
*
* #author
*/
void onHowToDetermineStock(){
Contract contract = new Contract();
Order order = new Order();
contract.m_symbol = "IBKR";
contract.m_secType = "STK";
contract.m_exchange = "SMART";
contract.m_currency = "USD";
order.m_action = "BUY";
order.m_totalQuantity = 100;
order.m_orderType = "LMT";
order.m_lmtPrice = enteredLmtPrice;
m_client.placeOrder(GlobalOrderId, contract, order);
}
public class IBApp {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
econnect(port=7496, clientid=0);
onHowToDetermineStock();
}
}
There are a number of problems with your code that make it an invalid Java program.
In Java, all methods must be contained within a class, unlike your onHowToDetermineStock method. Also, unlike R, Java doesn't use named parameters (i.e. port=7496 is not valid except to assign a variable named port). There are other problems.
Java is an object-oriented language and is very different from R. I would suggest forgetting the IB API for the time being, and spending some time learning how to code a basic Java application. There are many free tutorials on the web.
E.g.: https://docs.oracle.com/javase/tutorial/
Related
My professor gave me these classes but when I try to run them it seems that AnimationNoApplet cannot find NoApplet the title is the error I receive. I have both files in the same folder and have tried switching the package names to be identical but no success.
This is AnimationNoApplet:
package noapplet.example;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.Timer;
import noapplet.NoApplet;
/** Reusable class implementing the animation idiom. */
#SuppressWarnings("serial")
public abstract class AnimationNoApplet extends NoApplet {
This is NoApplet
package noapplet;
#SuppressWarnings("serial")
public class NoApplet extends JPanel {
There is many lines to the two files but I believe this is the root of the problem. Another thing that I noticed was the class made for AnimationNoApplet was NoApplet$1.class. I'm not sure if this is relevant information but I thought I should call it out. The last thing I want to call out is that this is on visual studio code I have not used another editor.
I am using selenium for web interaction and I need to use import com.google.common.io.Files for it to work. However, I also need to use import java.nio.file.Files; for some files that I work with. I don't know what to do because java doesn't allow for import aliasing as far as I can tell. Is there any way to cope with this? Let me know if I need to provide any other details
The "import java.nio.file.Files:" is only used for the ".readString(Path)" So if there is another way to get the contents of a file as a string from a "Path" please let me know.
The import java.nio.file.Files; is also used only inside a method if there is any weird obscure way to only import for the method.
You can import one File class to access directly by its name. Furthermore you can access your second File class by its full qualified name. e.g.
import com.google.common.io.Files;
...
Files f = new Files()
f.yxz();
java.nio.file.Files a = new java.nio.file.Files()
a.abc()
The workaround is to import one and use the fully qualified name for the other.
import java.nio.file.Files;
MyClass {
Files.list(...); // refers to Files from java.nio
com.google.common.io.Files.getFileExtension(...)
}
Specifically, I am trying to enable .SVG files to be usable by the core image component.
Right now I am making a sling model that ideally I would like to access the returned values of the getSrc() and getFileReference() classes in the core AEM Component interface located here.
I am very new to AEM development and Sling models. Am I missing some vital functionality that would let me do this?
Here is my code, which probably isn't at all helpful at this point.
package com.site.core.models;
import com.adobe.cq.wcm.core.components.models.Image;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.annotations.*;
import org.apache.sling.models.annotations.injectorspecific.*;
import org.apache.sling.settings.SlingSettingsService;
import javax.jcr.Node;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
#Model(adaptables = SlingHttpServletRequest.class)
public class ImageModel {
private String src = Image.getSrc();
return src;
}
As I mentioned in my comment, the link you are referring to is an interface, the implementation of that interface is here
In order to use your own implementation, you have two options:
In the image component html, change the data-sly-use to refer to your impl: com.site.core.models.ImageModel
Create a separate model that implements the Image interface and give it a high ranking to be picked up instead of the existing impl.
Disclaimer: I have not tested #2 but the documentation suggests that it's possible.
this error seems trivial, but it won't go away. I have the following class defined:
import java.io.IOException;
import java.util.Iterator;
import java.util.StringTokenizer;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapred.TextOutputFormat;
import org.apache.hadoop.mapreduce.Mapper;
public class Anagram_Mapper extends Mapper<LongWritable, Text, Text, Text> {
in the 'main' function i am trying to use JobConf to launch a simple mapreduce:
public static void main(String args[]){
JobConf conf = new JobConf(Anagram_Mapper.class);
conf.setJobName("anagram_mapper");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Anagram_Mapper.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
try {
JobClient.runJob(conf);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Eclipse is throwing an error on this line:
conf.setMapperClass(Anagram_Mapper.class);
the error is:
The method setMapperClass(Class<? extends Mapper>) in the type JobConf
is not applicable for the arguments (Class<Anagram_Mapper>)
but, as you can see above, my Anagram_Mapper class extends Mapper, right? so, i don't understand why this error....
EDIT: someone posted here, then retracted their post, but it helped steer me in the right direction. apparently i am using:
org.apache.hadoop.mapreduce.Mapper
but JobConf.setMapperClass accepts only:
org.apache.hadoop.mapred.Mapper
now i'm a little confused about the difference, they seem to be fundamentally the same, and the API tells me they are both valid in Hadoop 2.2.0, the version i'm using....
Indeed you are mixing the old mapred API with the new mapreduce API.
Basically Hadoop mapreduce supports two incompatibles APIs and you have to decide which one to use. I can be confusing because they share classes with same or similar names. You should carefully look at your import statements.
Both API can achieve almost the same thing. mapred has not been deprecated nor removed to no break legacy applications. mapreduce is the same API with a slightly better design.
If you are starting a new project, I would advise to use the new one. But it is not a big deal. The easy fix is to change your org.apache.hadoop.mapreduce.Mapper import statement.
Faced same error after writing Driver class, below is the error
The method setReducerClass(Class) in the type Job is not applicable for the arguments (Class)
reason of getting this error : after creation of reducer class i have immediately passed the class name in setReducerClass(); without defining the reducer class.
The function is expecting a class name that actually extends Reducer, it will throw same error until the passed argument is as per the method expected argument type.
I am working in an Android project recently. Our project uses a computer vision library called boofcv:
http://boofcv.org/index.php?title=Main_Page
After importing the library source code into our project, I found that Android Studio cannot revolve symbols from sun.awt.image.* and java.awt.color.ColorSpace.
package boofcv.core.image;
import boofcv.struct.image.*;
import sun.awt.image.ByteInterleavedRaster;
import sun.awt.image.IntegerInterleavedRaster;
import sun.awt.image.ShortInterleavedRaster;
import javax.swing.*;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.*;
import java.lang.reflect.Array;
/**
* Functions for converting to and from {#link BufferedImage}.
*
* #author Peter Abeles
*/
public class ConvertBufferedImage {
......
But then I wrote a very simple test program and found that my jdk did contain those classes. my program:
import sun.awt.image.ByteInterleavedRaster;
import sun.awt.image.IntegerInterleavedRaster;
import sun.awt.image.ShortInterleavedRaster;
import javax.swing.*;
import java.awt.*;
import java.awt.color.ColorSpace;
import java.awt.image.*;
class test{
public static void main(String[] args) {
ByteInterleavedRaster b;
IntegerInterleavedRaster i;
ShortInterleavedRaster s;
ColorSpace c;
System.out.println("testing");
}
}
Did I miss some configuration or it is just the issue of Android Studio?
Any help is greatly appreciated.
Don't use the visualization package for anything on Android. It's based off on swing which isn't supported on Android. Use the android package in integration. It has similar functions for visualizing data.
https://github.com/lessthanoptimal/BoofAndroidDemo
that might be useful for you.