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.
Related
So I am stuck with a problem when debugging with the most recent version of Eclipse 2020-03, which I installed for a new project I'm working on.
It first struck me that things were not working correctly when I couldn't read a resource with Class.getResource( String name ), as the debugger at the breakpoint in getResource(..) kept telling me that the name was null, while I definitely had provided a path name.
Clearing, cleaning, reloading the target (Running Platform), refreshing and rebuilding did not change anything, so I decided to create a simple OSGI plugin project with just an Activator, and a debug configuration with only the bare minimum bundles.
The Activator looks like this:
public class Activator implements BundleActivator {
public static final String BUNDLE_ID = "test.myapp.core";
private static BundleContext context;
private Logger logger = Logger.getLogger(this.getClass().getName());
static BundleContext getContext() {
return context;
}
public Activator() {
super();
logger.info("STARTED: " + BUNDLE_ID);
}
#Override
public void start(BundleContext bundleContext) throws Exception {
logger.info("ACTIVATED: " + BUNDLE_ID);
Activator.context = bundleContext;
InputStream in = getClass().getResourceAsStream( "/test.cfg" );
}
#Override
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
}
EDIT: Changed the original link to build.properties to test.cfg in order to avoid confusion.
But when I start the debugger, it will activate the bundle, but will not show any of the log messages. Also the debugger will not respond to the breakpoints I put in. Strangely enough, selecting 'ss' shows me far more bundles than the ones provided in the debug configuration.
id State Bundle
0 ACTIVE org.eclipse.osgi_3.15.200.v20200214-1600
1 ACTIVE test.myapp.core_1.0.0.qualifier
2 ACTIVE org.apache.lucene.core.source_8.4.1.v20200122-1459
3 ACTIVE javax.annotation.source_1.2.0.v201602091430
....
It seems as if a different debug configuration is launched, and is using an previously built version of my bundle, where the log messages were not yet included. clearing the bin folder, and eventually all the metadata also had no effect.
I'm totally stumped as of what I'm experiencing here. Hopefully someone can help!
Well..as it seems, I found out what was wrong. There were two problems that were occuring all at once:
1: Regarding the problems with getResource( String name). The Bundle-ClassPath setting in Manifest.MF MUST include . (see https://www.eclipse.org/forums/index.php/t/287184/), so in my case:
Bundle-ClassPath: .,
test.myapp.core
Bundle-ClassPath is not added automatically by the plugin wizards, so that can cause some problems.
2: The Debug configuration screen in the new IDE seems to be very slow, and does not change the selected bundles if you switch from "only show selected" and back. As a result, the previous list of bundles remained active, while they were unchecked in the Debug Configuration Editor.
I'll file a report for these issues
ADDITIONAL
So I have made some further investigations on the Bundle-ClassPath issue, and what probably has happened that this entry in the Manifest.MF occured when adding some libraries. After they were removed again, the Bundle-ClassPath entry remained, and caused all sorts of problems. If you ever:
1: Notice that certain classes from bundle A cause a NoClassDefFound exception when used in bundle B
2: The build.properties file from bundle A give a warning that sources are missing
3: Other bundles don't seem to give that problem
Check to see if there is a Bundle-ClassPath entry in your Manifest.MF file. Most probably that entry is causing the problems. Either remove the entry in the manifest, or add ,. at the end.
see:
1: What is the intended use case for Bundle-Classpath in OSGI bundles
2: https://bugs.eclipse.org/bugs/show_bug.cgi?id=139271
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
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
I booted up eclipse to start on a project, and without typing in a word I already have several errors.
package department.namespace;
import android.app.Activity;
import android.os.Bundle;
public class DepartmentActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
At package department.namespace, it says:
multiple marks at this line and the type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
The import android.os cannot be resolved.
Override cannot be resolved as a type
The method OnCreate(Bundle) is undefined for the type Activity
R. cannot be resolved as a variable.
Since this JUST came up when I started Eclipse, how do I fix this?
First, you should start by cleaning and building the project. This can be done by selecting the project of interest and then selecting the appropriate option from the project menu.
If that doesn't resolve the issue, then I would recommend checking the projects build path to ensure that your expected dependencies are present and accounted for. If I remember correctly when I have had this issue in the past, it helps to remove and re-add the JRE of choice.
To look into this issue further, you might check some of the following links:
Android Dev Specific - http://kyleclegg.com/eclipse-android-error-type-cannot-be-resolved/
http://dev-answers.blogspot.com/2009/06/eclipse-build-errors-javalangobject.html
http://www.adriancourreges.com/articles/the-type-java-lang-object-cannot-be-resolved-with-eclipse/
I currently have Java ME SDK 3.0.5 installed and am running a MIDLET from Eclipse.
When I run the app under the emulator device I get the following data in the console:
Syntax:
emulator [arguments]
In order to get commands supported by given device run:
emulator.exe -Xdevice:<device name> -Xquery
Generic list of arguments is:
-version Display version information about the emulator
-help Display list of valid arguments
-classpath, -cp The class path for the VM
-D<name>=<value> Set a system property
-Xdebug Use a remote debugger
-Xrunjdwp:[transport=<transport>,address=<address>,server=<y/n>,
suspend=<y/n>]
Debugging options
-Xdevice:<device> Select a device skin for the emulator
-Xdomain:<domain_name>
Set the MIDlet suite's security domain
-Xmain:<main class name>
Run the main method of a Java class, as in Java SE
-Xquery Print device information
Everything seems to be alright, but I can't get any form of emulation to appear.
here is the code of my MIDLET, although I don't think the problem lies here.
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
public class Hello extends MIDlet implements CommandListener {
private Command exitCommand;
private Display display;
private Form screen;
public Hello() {
display = Display.getDisplay(this);
exitCommand = new Command ("Exit", Command.EXIT, 2);
screen = new Form ("Hello World");
StringItem strItem = new StringItem ("","Hello World");
screen.append (strItem);
screen.addCommand (exitCommand);
screen.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
// set the current display to the screen
display.setCurrent(screen);
}
public void pauseApp() {
// TODO Auto-generated method stub
}
public void destroyApp(boolean unconditional) {
// TODO Auto-generated method stub
}
public void commandAction (Command c, Displayable s)
{
if (c == exitCommand)
{
destroyApp (false);
notifyDestroyed();
}
}
}
The output is pretty simple, it's telling you that the command line syntax to the emulator is incorrect.
Go to the Java ME device settings and edit the emulator command line / start options to suit.
Switching IDE's may work for you as a short-term fix, but it's always better to get to the root of the issue. Plus it'll help you understand the emulator framework.
I switched over to Netbeans, which has integrated support for J2ME (as opposed to having to install a 3rd party plugin for Eclipse) and it now works perfectly.
I had a similar problem while running a basic JavaMe app on eclipse, "Corrupt JAR, error while reading". It worked for me after I followed this series for starters http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.mtj.doc.user/html/gettingstarted/prepare_workbench.html (try not to miss anything mentioned here).
Note, when you launch the app, use "Launch as emulated Java ME JAD"(-in the top right "Running" section on the page) from the "Application descriptor" (-from left menu.)
This is a late reply but might just help someone in future.
If you are adventurous and want to develop / run JavaME application without IDE's than I have some ray of hope, write a batch script (or shell script for linux system) to manually run the emulator with specific jad
Batch Script (run.bat)
"<javame-3.0-sdk-root-folder>\bin\emulator.exe"
-Xdescriptor:"<jad-filename-with-extension>" >> logs.txt
pause
exit
save the above script in the same folder as the application jad/jar. The console prints will be available in log.txt file.
Here is post how to run jar from emulator (Java ME SDK 3.0.5)
(How to run MIDLET in Java ME SDK 3.0.5 ::http://madhukaudantha.blogspot.com/2012/10/how-to-run-midlet-in-java-me-sdk-305.html