Eclipse debug can not step into (or F5) - eclipse

package com.test;
import java.util.TreeMap;
public class Main {
public static void main(String[] args) throws Exception {
TreeMap<String, String> tree = new TreeMap<String, String>();
tree.put("1", "1");//line a
tree.put("1", "1");//line b
System.out.println(tree.size());
}
}
I want to debug TreeMap put method, so i add two breakpoints for the lines (line a,line b).
Eclipse debug tool cannot step into put mentod when debugging.
I have attached source code for eclipse. when i put mouse over put method, press F3 key, it can go to TreeMap put method source code. I am running Eclipse SDK Version: 3.2.2

download the source code from this link : http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/TreeMap.java and then attach this source into eclipse

Related

Could not find main method from given launch configuration

I've a simple Java project that works when I execute it at Eclipse environment. But when I try to export it to a Runnable Jar, I get the following error:
JAR export finished with warnings. See details for additional information.
Exported with compile warnings: JavaSwing/src.main.java/com/cansoft/GUIProgram.java
Exported with compile warnings: JavaSwing/src.main.java/com/util/Util.java
Jar export finished with problems. See details for additional information.
Could not find main method from given launch configuration.
I read other posts which suggest to create a MANIFEST.MF file specifying the main-class which I did. It is placed at MyProjectFolder/META-INF/MANIFEST.MF and it contains the following information:
Manifest-Version: 1.0
Class-Path: resources
main-class: com.cansoft.GUIProgram
My main class is as follows:
public class GUIProgram {
private JFrame folderCreationSubappFrame;
private Color color;
private String home;
private final static Logger LOG_MONITOR = Logger.getLogger("com.cansoft");
public static void main(String[] args) {
try {
new GUIProgram();
} catch (Exception e) {
LOG_MONITOR.log(Level.INFO,e.getMessage());
}
}
public GUIProgram() throws InterruptedException, SecurityException, IOException {
home = System.getProperty("user.home") + File.separator + "Documents";
startLogSystem();
if(isFirstRun()) {
showWelcomeFrame();
} else {
initialize();
}
} .... More and more code
Does anybody know what am I missing? Any help much appreciated.
Thank you.
It is not enough to create the manifest file, you need to explicitly choose it in the Eclipse jar export dialog.
Answer to Comment
If you use "runnable jar", make sure that you chose the correct launch configuration and that the launch configuration successfully runs when chosing "Run As" -> "Run Configurations" -> "Java Application" -> Your Configuration -> "Run"
I finally find out where the problem was, it was quite simple btw. I had created my GUIProgram within a src.main.java package, but that package was created (my bad) as resources instead of folders, so Eclipse was smart enought to run it but when trying to generate the JAR which expected a correct java project structure, it was failing because truly there were not GUIProgram java class at src path (src was not folder type but resources).
Hope I succeed explaining.

"Source not found" when clicking on stacktrace

Usually, clicking on a line in the stacktrace, the source file opens at the offending line. With Eclipse-oxygen (R with support for java9 installed) and java9 (u175) it shows a dialog "Source not found" if the source is somewhere inside the java modules. Source is found as expected, when navigating (by F3) in the editor.
What's/where's wrong and how-to fix it?
Below is a simple two-liner example which fails, showing the stacktrace:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 5 out-of-bounds for length 0
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:372)
at java.base/java.util.ArrayList.set(ArrayList.java:453)
at dummy.PlainStacktrace.main(PlainStacktrace.java:10)
The two-liner:
import java.util.ArrayList;
public class PlainStacktrace {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.set(5, "error");
}
}
This was bug 518829, which should be resolved in recent builds.
NB: until Java 9 and Eclipse support for it are officially released, it may be a good idea to regularly updated not only JDK but also the Eclipse part.

Selenium-java-3.0.0-beta2 jar files are not working in eclipse

I'm new to selenium, I've tried to automate a simple task, but the build path option is not working in eclipse. I've attached few files here. Please help me to run this code.
Here is the code for that:
package seleniumTutorial;
public class SeleniumGoogleMain {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
driver.findElement(By.linkText("Gmail")).click();
driver.findElement(By.id("Email")).sendKeys("jssjohny");
driver.findElement(By.name("signIn")).click();
}
}
Here is the download list for selenium :
These are the jar files I've included, but it's not working still :
Thanks in advance.

Importing greenDAO from eclipse to Android studio 1.0 RC 2 [duplicate]

I'm looking for a clear step-by-step explanation on how to import GreenDao in Android Studio.
I've used it before in AS, but failed to get it to work again.
There are some tutorials out there, but they don't seem to apply to the latest version of AS.
When I clone from github, I get a example project stuff etc.
Is there a way to install GreenDaoGenerator without these extras?
Just looking for an up-to-date step-by-step explanation.
Update: I suggest using Realm.io now! Check it out! :-)
Any help would be appreciated!
Tested on Android Studio 2.0
With Android Studio 0.6.1+ (and possibly earlier) you can easily add non android project to your android project as a module.
Using below method you can have Java modules(greenDaoGenerator) and Android modules in the same project and also have the ability to compile and run Java modules as stand alone Java projects.
Open your Android project in Android Studio. If you do not have one,
create one.
Click File > New Module. Select Java Library and click Next.
Fill in the package name, etc and click Finish. You should now see a
Java module inside your Android project.
Open the build.gradle file of the java project and add the following dependency
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('de.greenrobot:DaoGenerator:1.3.0')
}
Copy your DaoGenerator classes or create if you don't have one to your java module.For e.g. I have created ExampleDaoGenerator class in my java module.
public class ExampleDaoGenerator {
public static void main(String[] args) throws Exception {
Schema schema = new Schema(1000, "de.greenrobot.daoexample");
addNote(schema);
new DaoGenerator().generateAll(schema, "../DaoExample/src-gen");
}
private static void addNote(Schema schema) {
Entity note = schema.addEntity("Note");
note.addIdProperty();
note.addStringProperty("text").notNull();
note.addStringProperty("comment");
note.addDateProperty("date");
}
}
Now, to generate the classes that you can use in android project follow below steps.
Click on the run menu in the top bar. Click Edit Configurations...
In the new window, click on the plus sign at the top left of the window and select Application
A new application configuration should appear, fill the following information.
Give it a name e.g. greenDao.
In main class click … button and select your generator class which have the main method.for e.g. in this case it is
com.greendao.generator.ExampleDaoGenerator
In working directory select path of your java project.
In use class of module select you java project.
click ok.
Again go to run menu and now you can see e.g. run greendao. click on it.It should compile successfully.
Its done !!! you can check your generated classes in the folder that you have specified.For e.g. in this case it is /DaoExample/src-gen
NOTE: You can run your android project again by clicking on run menu -> Edit Configuration . select your project and click ok.
Here's a step by step overview for Integrating GreenDao into your Android Project.
[ Reference How to use GeenDao with Android ? ]
[Project Link: GreenDao Example ]
PART1 : Setting Up GREENDAO
Create an android project.
Click File >New > New Module. Select Java Library and click Next.
Now we have to add the following Gradle Dependencies.
In build.gradle of Module:app, insert
compile 'de.greenrobot:greendao:2.1.0'
In the build.gradle of Module:greendao-generator, insert
compile 'de.greenrobot:greendao-generator:2.1.0'
Make sure, you sync your project.
Now in the MainGenerator.java,
we will define the database structure.
import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Schema;
public class MainGenerator {
public static void main(String[] args) throws Exception {
//place where db folder will be created inside the project folder
Schema schema = new Schema(1,"com.codekrypt.greendao.db");
//Entity i.e. Class to be stored in the database // ie table LOG
Entity word_entity= schema.addEntity("LOG");
word_entity.addIdProperty(); //It is the primary key for uniquely identifying a row
word_entity.addStringProperty("text").notNull(); //Not null is SQL constrain
// ./app/src/main/java/ ---- com/codekrypt/greendao/db is the full path
new DaoGenerator().generateAll(schema, "./app/src/main/java");
}
}
Run MainGenerator.java
After running this, you will observe a newly created folder i.e. db in the Main Project Folder.
PART2 : Integrating it with Android Project
Set the activity_main.xml layout.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textData"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save"
android:id="#+id/textSave"
android:layout_below="#+id/textData"
android:layout_alignEnd="#+id/textData"
android:layout_marginTop="22dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Top"
android:id="#+id/textTop"
android:layout_below="#+id/textSave"
android:layout_alignParentStart="true"
android:layout_marginTop="35dp" />
In MainActivity.java,
Add the following codes
package com.codekrypt.greendao;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.codekrypt.greendao.db.DaoMaster;
import com.codekrypt.greendao.db.DaoSession;
import com.codekrypt.greendao.db.LOG;
import com.codekrypt.greendao.db.LOGDao;
import java.util.List;
public class MainActivity extends AppCompatActivity {
//Dao --> Data Access Object
private LOGDao log_dao; // Sql access object
private LOG temp_log_object; // Used for creating a LOG Object
String log_text=""; //Entered text data is save in this variable
private final String DB_NAME ="logs-db" ; //Name of Db file in the Device
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Initialise DAO
log_dao=setupDb();
//Setting up form elements
Button textSave= (Button) findViewById(R.id.textSave);
Button textTop= (Button) findViewById(R.id.textTop);
final TextView textData=(TextView) findViewById(R.id.textData);
assert textSave != null;
textSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
log_text=textData.getText().toString();
temp_log_object=new LOG(null,log_text);// Class Object, Id is auto increment
SaveToSQL(temp_log_object);
}
});
assert textTop != null;
textTop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
textData.setText( getFromSQL() );
}
});
}
//---------------------------------SQL QUERY Functions-----------------------------------------//
public String getFromSQL(){
List<LOG> log_list = log_dao.queryBuilder().orderDesc(LOGDao.Properties.Id).build().list();
//Get the list of all LOGS in Database in descending order
if(log_list.size()>0) { //if list is not null
return log_list.get(0).getText();
//get(0)--> 1st object
// getText() is the function in LOG class
}
return "";
}
public void SaveToSQL(LOG log_object) {
log_dao.insert(log_object);
}
//----------------------------***END SQL QUERY***---------------------------------------------//
//-------------------------------DB Setup Functions---------------------------------------------//
//Return the Configured LogDao Object
public LOGDao setupDb(){
DaoMaster.DevOpenHelper masterHelper = new DaoMaster.DevOpenHelper(this, DB_NAME, null); //create database db file if not exist
SQLiteDatabase db = masterHelper.getWritableDatabase(); //get the created database db file
DaoMaster master = new DaoMaster(db);//create masterDao
DaoSession masterSession=master.newSession(); //Creates Session session
return masterSession.getLOGDao();
}
//-------------------------***END DB setup Functions***---------------------------------------//
}
Before Running the App, Make sure you have changed your configuration.
Now Run it.
PART 3 – VIEW THE SQL DB
Open Command Prompt.
Enter the following commands.
Opening the db file in SQLite3
Using SQLite3
PART 4 – EXTRAS
Structure (Core Classes) of GREENDAO
I have used this tutorial for Android Studio 0.8.9 and everything works fine.
Works on Android 1.3 Preview
For the top answer ( Tested on Android Studio 1.0 ), you might need to include that source folder in your project. Go to app/build.gradle
add the following inside android block
sourceSets{
main{
java{
srcDir 'src-gen'
}
}
Solution: IO-Exception
Go to the build from your dao generator.
add: apply 'application'
add: mainClassName = "you.package.include.Main"
execute "run" in application task (gradle task)
I dont know why it doesnt work when you create manually a run configuration.
Basically, what you need is to add a Java library module (File > New > New module..) to your Android project (assuming you're using Android Studio), and insert the generation code inside public static void main(String[] args) {} in this module's .java class. Then Run it and the code will be generated in you main app's module.
See this blog post for a step by step tutorial with explanation.

Eclipse Unresolved compilation

I have this really weird problem working on a bigger project in Eclipse Indigo 3.7.2.
I checked out the project from an SVN repository using the Subclipse plug-in and when I start the application I get the following error message:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at anares.preprocess.StanfordParser.getInstance(StanfordParser.java:73)
at anares.start.Startconsole.<init>(Startconsole.java:22)
at anares.start.Startconsole.main(Startconsole.java:52)
This is what Startconsole.class looks like, containing the main method:
package anares.start;
import java.io.FileNotFoundException;
import java.io.IOException;
import anares.core.AnaResAlgorithm;
import anares.preprocess.MorphaDornerSentenceSplitter;
import anares.preprocess.CollectionEquipper;
import anares.preprocess.ParserHandlerInterface;
import anares.preprocess.Preprocessor;
import anares.preprocess.SplitterInterface;
import anares.preprocess.StanfordParser;
import anares.text.AnaResTextObject;
public class Startconsole {
public final ParserHandlerInterface parserint = StanfordParser.getInstance();
public final SplitterInterface splitterint = MorphaDornerSentenceSplitter.getInstance();
public final CollectionEquipper equipperint = null;
public final static int buffersize = 5;
private Startconsole(String file) throws IOException {
AnaResTextObject object = startPreprocess(file);
startAlgorithm(object);
}
private AnaResTextObject startPreprocess(String file) throws IOException {
Preprocessor prepro = new Preprocessor(parserint, splitterint,
equipperint);
AnaResTextObject textObject = prepro.preprocessText(file);
return textObject;
}
private void startAlgorithm(AnaResTextObject object) {
AnaResAlgorithm algo = new AnaResAlgorithm(buffersize);
algo.resolveAnaphora(object);
}
public static void main(String args[]) throws FileNotFoundException,
IOException {
if(args.length > 0){
Startconsole console = new Startconsole(args[0]);
}else{
Startconsole console = new Startconsole("Text.txt");
}
}
}
As I was saying this is a bigger project and therefore contains a few .jar-files and references to other packages.
This problem only occurs on my laptop. On my other PC everything works fine, and a fellow student of mine, who works on the same project, does not have any problems either.
I already tried checking the project out again, cleaning it up and even reinstalling eclipse.
Now here's the weird part: If I comment out the whole main method, just leaving something like
public static void main(String args[]) throws FileNotFoundException,
IOException {
// if(args.length > 0){
// Startconsole console = new Startconsole(args[0]);
// }else{
// Startconsole console = new Startconsole("Text.txt");
// }
System.out.println("Hello World!");
}
I still get the exact same error message with the exact same line numbers. And no "Hello World!" in the output.
Does anyone have any ideas where the problem comes from?
Your issue seems like either there is an error in the code that I cannot see, or your Eclipse instance/compiler got into a strange state it cannot recover from.
Just some basic ideas to check
Have you tried restarting Eclipse?
Are you using the same version of Java on all computers? E.g. there might be some incompatibilities between Java 6 and Java 7.
Is automatic build turned on? Look in the Project/Build automatically menu item. It is possible that the automatic Java builder got turned off, and thus it does not recompile your code.
Have you tried to clean your project to force a rebuild? (Project/Clean menu item).
Is JDT installed in your Eclipse instance? It should be, but it might worth check for such trivial issue.
Maybe you should try to create a new workspace, and checkout the projects again.
You could also try to download Eclipse again with this new workspace idea.
If neither of these things work, I have no idea what to look for.
Look in Eclipse's Problems view (tab); any compilation problems in the project will be reported there. You can double-click on an error or warning in the Problems view and the editor will open on the specific line that is a problem.
Do one thing just remove the build path of englischPCFG.ser.gz from your project because i am sure this is not the jar file you have added in your project