I'm having a problem with my test application which is follows. I'm having following code:
#Test(expected = InvalidStateException.class)
public void testLiianPitkaKayttajatunnus()
{...}
I'm using Eclipse and it says "InvalidStateException cannot be resolved to a type" and as we know if eclipse notice a problem it underline it with red wave line. I have been trying to search solutions but still not found any. I have tried following things but none of them has solved the problem:
Adding org.apache.openjpa dependency to my pom.xml and adding line before class code "import org.apache.openjpa.persistence.InvalidStateException;"
In thread, it is said that if you have in your class extension of other class, it should be taken out. This didn't helped neither.
In the same thread one advice is to use JUnit 4.4 and it didn't helped neither.
So my question is how this problem can be solved?
For additional information, my class start follows (imports are not mentioned here)
public class TietorakenneTest extends TietokantaTestCase {....} and JUnit version that I use is 4.10,
any help is appreciated. If you need any other information about the code, please let me know and I will put them here.
Qualify the class by adding the package name.
#Test(expected = org.apache.openjpa.persistence.InvalidStateException.class)
Change your import statement to
org.apache.openjpa.util.InvalidStateException and as you mentioned add org.apache.openjpa dependency to my pom.xml
Hope it helps.
Related
I am writing a simple Java test using JUnit and constantly get the following error: Class not found: "md.leonis.ServiceMagi?Test". I don't see any stacktrace.
Recommendations for this ticket did not help: Class Not Found Exception when running JUnit test
I invalidated the InteliJ Idea cache, recompiled the project, with no result. Example class:
public class ServiceMagiсTest {
#Test
public void test() {
assertTrue(true);
}
}
Who faced this before?
I figured it out myself. For some mysterious reason, one letter in the class name has been replaced with a similar letter from the Russian alphabet. IDE gave a hint:
Identifier contains symbols from different languages: [LATIN, CYRILLIC]
Non-ASCII characters in an identifier
Hope this helps someone.
I try to use the #NotNull annotation from package com.sun.istack.internal.
I am using IDE Intellij IDEA Community Edition.
when I build a program using IDE no problem. When I try to compile a file from the command line using javac, I get an error "cannot find symbol".
package ibkr;
import com.sun.istack.internal.NotNull;
public class Main {
public static void main(String[] args) {
test("Test");
}
public static void test(#NotNull String text) {
System.out.println(text);
}
}
I don't understand why i can't compile this code using javac and how Intellij IDEA make compilation and run it.
The annotation is an internal class, it's not for public use. The closest alternative is Jetbrains' stuff:
https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html
Even if the class is in the classpath, it doesn't necessarily mean that you can safely refer to that class. The compiler can have some limitations upon accessing some classes/packages.
In most cases, as here, it's obvious whether the package is internal or not: com.sun.istack.internal. Oracle discourages developers from using classes from such packages.
Ok i know this question is a bit old, but if my info is correct, the reason for this is the fact that intellij uses full rt.jar for compilation while javac uses incomplete version, because of ct.sym
This is an annotation used to identify non-nullable values, also this will let static analyzer have their checks in place. In case you are using IntelliJ you can use its annotation but it would make it very tool-specific, same is the case for eclipse
One can also you
https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl
This provides the same non-null annotation but you need to add an extra dependency there.
I am following Prinston's course Algorithms, Part I. As I came from .NET and just started to use Java, I have some issue with a piece of Java code and I can not find any related information. They provide with a code which I can use for reading a text file:
public static void main(String[] args) {
In in = new In(args[0]);
int n = in.readInt();
...
}
Exception thrown:
In cannot be resolved to a type
What is this In? Should I import some package or what should I do?
The whole code and description can be also seen here: http://coursera.cs.princeton.edu/algs4/assignments/collinear.html
You need algs4, provided by Princeton as well. When it's in the classpath, add
import edu.princeton.cs.algs4.In;
If that's the only class, you could use the source of In.java.
But I doubt that's allowed on Coursera: when you submit code, it will probably be compiled on the server with algs4.jar in the classpath, so you should really use that one and not your own code.
In.java seems to be a class that someone at princeton made, probably for that same course: http://algs4.cs.princeton.edu/12oop/In.java.
So, yes, you need to import the correct package and you need a jar with that class in your classpath. Search your course documentation for more hints.
i am having a problem when using reflections. I have this code in a project, which is implemented as maven dependency by other projects to find testNG test classes. So, as i haven't got a particular package, i was passing it empty and it was finding successfully classes i want when i execute locally. Here is my code:
String pack = StringUtils.EMPTY;
this.reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(pack)).setScanners(
new MethodAnnotationsScanner()));
this.testNGTests = this.reflections.getMethodsAnnotatedWith(org.testng.annotations.Test.class);
But i have the problem that when i execute it remotely it can't find any classes. So i was thinking that i must pass it something at package parameter. So, i want to know if any of you have and idea about that happens behind reflections when i pass empty package and why is working. Do you know something that could help me? Thank you!
I've already fixed my problem. I changed the setting for package by forJavaClassPath. Thanks you! Yet, if any of you could give me some more information it will be well recieved! Regards
I am using JasperReports 5.6 via API. I am building a report using iReport. The problem is that I've already set a jar with bean factory in the classpath of iReport as
com.myname.beanproject.beanpackage.BeanFactoryClass
Also I set up static method to call a list of beans:
getListEntries
but still getting a error while testing a connection. What am I doing wrong?
Error is not helpful at all:
General problem: null
As I can see, the problem is not in classpath neither factory: when I change any, the error is changing either to
"No class found"
(if I add something to class name)
or
"General problem: com.myname.beanproject.beanpackage.BeanFactoryClass.getListEntries11111()"
(if I add 11111 to the name of factory method to test)
Your getListEntries() method should be static and public too
that way , ireport can deal with it :)
i ran into the same problem, i had put my method like that
protected static getmyBeans().....
i fix the connection test after i put
public static getmyBeans().....
in my factoryClass
so check your method defenition
and dont forget to rebuild your jar code
and restart ireport
good luck, and sorry if i do mistakes in my english language
I just ran into the same problem. Your getListEntries() method should be static. That fixed it for me.