java.lang.ExceptionInInitializerError using MVC - java

I get this error when I try to compile my code. I am not sure what is wrong with it and I don't understand what is the error saying. Here is the error messaged followed by the lines where it says it errors:
Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
at g52gui.C_login.<clinit>(C_login.java:9)
at g52gui.V_login.<init>(V_login.java:6)
at g52gui.V_login$4.run(V_login.java:181)
...
and the lines where it errors:
line 9 C_login (controller): private static final C_home controller_home = new C_home();
line 6 V_login (view): private final C_login controller_login = new C_login();
line 181 V_login (view): new V_login().setVisible(true);
It seems like the problem comes from the C_home but there is no compilation errors in there.
EDIT
I think the problem might be here, in C_login:
public class C_login {
private static final V_login view_login = new V_login();
private static final M_login model_login = new M_login();
private final static C_home controller_home = new C_home();
private static final C_registration controller_regi = new C_registration();
private static final MySQLAccess sql_connection = new MySQLAccess();
public static void main(String[] args) throws Exception {
view_login.setVisible(true);
}
public static boolean login_button_clicked(String usrn, String psw){
String login = M_login.login(usrn, psw);
if (login == "ok"){
controller_home.start_view(usrn);
view_login.setVisible(false);
} else if (login == "fail" ) {
view_login.error_login();
return false;
} else {
view_login.error_connection();
return false;
}
return false;
}
I delcare C_home controller_home as static so I can access it later. Would there be another way to go around this and could this be the problem ?
EDIT
here are the Initializer in C_Home:
public class C_home {
private static final V_home view_home = new V_home();
private static final M_home model_home = new M_home();
private String username = "";
/* attributes for 3d model */
private BranchGroup sceneBranchGroup = null;
private RotationInterpolator rotator = null;
private Canvas3D offScreenCanvas3D = null;
private ImageComponent2D imageComponent = null;
private static final int offScreenWidth = 200;
private static final int offScreenHeight = 200;

Related

I can't print colors in terminal with my Java Application

I am working on a project and I figured out that when i try to print the ANSI color code, the application interpretate the code color as a <-, as you can see in the images.
Terminal Outut:
My color codes:
public final class BaseCodigoCores {
public static final String ANSI_RESET = "\u001B[0m";
public static final String TEXTO_ANSI_BLACK = "\u001B[30m";
public static final Cor ANSI_RED_BACKGROUND = new Cor("Vermelho","\u001B[41m");
public static final Cor ANSI_GREEN_BACKGROUND = new Cor("Verde","\u001B[42m");
public static final Cor ANSI_YELLOW_BACKGROUND = new Cor("Amarelo", "\u001B[43m");
public static final Cor ANSI_BLUE_BACKGROUND = new Cor("Azul","\u001B[44m");
public static final Cor ANSI_PURPLE_BACKGROUND = new Cor("Roxo","\u001B[45m");
public static final Cor ANSI_CYAN_BACKGROUND = new Cor("Ciano", "\u001B[46m");
public static final Cor ANSI_WHITE_BACKGROUND = new Cor("Branco","\u001B[47m");
}
Would like to know how to change that configuration to able my terminal to print colors.

I am not getting FLAVOR string in BuildConfig , it is Missing in BuildConfig in Android Studio

How to generate the missing one ? public static final String FLAVOR = "";`
Missing FLAVOR in BuildConfig in Android Studio.It should be like this
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.arkam.konk.look";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0.0";
}
But in my case getting like without this one public static final String FLAVOR = "";
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.arkam.konk.look";
public static final String BUILD_TYPE = "debug";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0.0";}
How to generate the missing one ???
use : Build -> Clean Project and then File -> Invalidate Caches / Restart. and then build your App on smartphone or emulator.
EDIT :
if it does't work, create a new project and copy your classes and codes in that!

ArangoDB creating graphs that are non-empty in Java?

I copied the following code from ArangoGraphTest.java:
private static final String GRAPH_NAME = "db_collection_test";
private static final String EDGE_COL_1 = "db_edge1_collection_test";
private static final String EDGE_COL_2 = "db_edge2_collection_test";
private static final String EDGE_COL_3 = "db_edge3_collection_test";
private static final String VERTEX_COL_1 = "db_vertex1_collection_test";
private static final String VERTEX_COL_2 = "db_vertex2_collection_test";
private static final String VERTEX_COL_3 = "db_vertex3_collection_test";
private static final String VERTEX_COL_4 = "db_vertex4_collection_test";
public static void testGraphCreate() {
final ArangoDB arangoDB = new ArangoDB.Builder().user("root").password("root").build();
final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<EdgeDefinition>();
edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
edgeDefinitions
.add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
final GraphCreateOptions options = new GraphCreateOptions();
ArangoDatabase db = arangoDB.db("TestArangoDB");
db.createGraph(GRAPH_NAME, edgeDefinitions, options);
}
After I ran this code the expected graph db_collection_test showed up in the web interface but it says "Your graph is empty." Is this expected and if so, how can I create a non-empty graph from Java?
This code just creates the collections in the database. There wont be any data unless you populate it. You should create all the vertices and edges as necessary.
Try creating some data with this snippet:
BaseDocument myObject = new BaseDocument();
myObject.setKey("myKey");
myObject.addAttribute("a", "Foo");
myObject.addAttribute("b", 42);
try {
arangoDB.db(dbName).collection(collectionName).insertDocument(myObject);
System.out.println("Document created");
} catch (ArangoDBException e) {
System.err.println("Failed to create document. " + e.getMessage());
}

Can't override node settings in ES integration test

I am writing an integration test for elasticsearch 5.3.
public class ProtectedWordsIndexTests extends ESIntegTestCase {
private final WordDelimiterActionListener wordsListener =
WordDelimiterActionListener.getInstance();
private final static String INDEX_NAME = "protected_words";
private final static String TYPE_NAME = "word";
private final static String FILTER_NAME = "my_word_delimiter";
#Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singleton(WordDelimiterPlugin.class);
}
#Override
protected Settings nodeSettings(int nodeOrdinal) {
return builder()
.put("plugin.types", TYPE_NAME)
.put("plugin.dynamic_word_delimiter.refresh_interval", "500ms")
.put(super.nodeSettings(nodeOrdinal))
.build();
}
public void testAddWordToIndex() throws Exception {
Settings indexSettings = builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put("index.analysis.filter.my_word_delimiter.type", "dynamic_word_delimiter")
.build();
TokenFilterFactory filterFactory = filterFactory(indexSettings, FILTER_NAME);
createIndex(INDEX_NAME);
ensureGreen();
client().prepareIndex(INDEX_NAME, TYPE_NAME, "1")
.setSource("word", "1tb")
.execute();
Thread.sleep(TimeValue.timeValueSeconds(1).getMillis());
Set<String> protectedWords = wordsListener.getProtectedWords();
assertTrue(protectedWords.size() == 1);
}
}
When I am running testAddWordToIndex() I am getting the following error:
"java.lang.IllegalArgumentException: unknown setting
[plugin.dynamic_word_delimiter.refresh_interval] please check that any
required plugins are installed, or check the breaking changes
documentation for removed settings"
If I remove the following part and increase the refresh interval to be more than the default, the test passes. So I just can't override this.
.put("plugin.dynamic_word_delimiter.refresh_interval", "500ms")
The default refresh interval is declared here:
public class WordDelimiterRunnable extends AbstractRunnable {
public static final TimeValue REFRESH_INTERVAL = TimeValue.timeValueSeconds(20);
public static final String INDEX_NAME = "protected_words";
public static final String INDEX_TYPE = "word";
public static final int RESULTS_SIZE = 10000;
private volatile boolean running;
private final Client client;
private final String index;
private final long interval;
private final String type;
public WordDelimiterRunnable(Client client, Settings settings) {
this.client = client;
this.index = settings.get("plugin.dynamic_word_delimiter.protected_words_index", INDEX_NAME);
this.type = settings.get("plugin.dynamic_word_delimiter.protected_words_type", INDEX_TYPE);
this.interval = settings.getAsTime("plugin.dynamic_word_delimiter.refresh_interval", REFRESH_INTERVAL).getMillis();
}
// more code here
}
You need to register the setting using the SettingsModule#registerSettings(Setting) method as explain here:
https://www.elastic.co/guide/en/elasticsearch/reference/5.x/breaking_50_settings_changes.html#breaking_50_settings_changes

Error in JUnit with static final List

I've written a JUnit where it is calling a Constant class, here we are trying to access a static final List
public static final List<String> SKIPPED_DIMENSION_LIST = new ArrayList<String>();
static{ SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_DISPLAY);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_SUB);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_SUB_GROUP);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_SUB_GROUP_ID);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_ID);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_GROUP_ID); }
Now, while accessing this List via JUnit thread I'm gettting this error.
java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
at com.mns.commerce.searchnav.constants.MSEndecaConstants.<clinit>(MSEndecaConstants.java:169)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at com.mns.commerce.searchnav.utils.MSSearchResposeBOTransformer.getRefinementsDetails(MSSearchResposeBOTransformer.java:460)
at com.mns.commerce.searchnav.utils.MSSearchResposeBOTransformer.buildFacets(MSSearchResposeBOTransformer.java:362)
at com.mns.commerce.searchnav.utils.MSSearchResposeBOTransformer.populateResults(MSSearchResposeBOTransformer.java:106)
at com.mns.commerce.searchnavunit.test.MSSearchResposeBOTransformerTest.testPopulateResults(MSSearchResposeBOTransformerTest.java:97)
Whereas, if an static Enum is defined instead of a static final list then it is working fine. Any idea why this is happening?
This code is also running and I don't have any error with this code. My JDK version is 1.6.
import java.util.ArrayList;
import java.util.List;
public class test {
private static final String PRODUCT_CATEGORY_DISPLAY = "a";
private static final String PRODUCT_CATEGORY_SUB = "b";
private static final String PRODUCT_CATEGORY_SUB_GROUP = "c";
private static final String PRODUCT_CATEGORY_SUB_GROUP_ID = "d";
private static final String PRODUCT_CATEGORY_ID = "e";
private static final String PRODUCT_CATEGORY_GROUP_ID = "f";
public static final List<String> SKIPPED_DIMENSION_LIST = new ArrayList<String>();
static{
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_DISPLAY);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_SUB);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_SUB_GROUP);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_SUB_GROUP_ID);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_ID);
SKIPPED_DIMENSION_LIST.add(PRODUCT_CATEGORY_GROUP_ID);
} /** * #param args */
public static void main(String[] args) {
System.out.println(SKIPPED_DIMENSION_LIST);
}
}

Categories

Resources