473,287 Members | 3,240 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

It is necessary that the code displays all objects

10 Byte
I wrote the code, but it displays only one object when loading, with the rest there is difficulty. Who faced similar situations, how did you solve similar situations?
And I also want to conduct a full code analysis in order to see all the errors at once, and not when loading the application into work. Are there any services?
Expand|Select|Wrap|Line Numbers
  1. public Bean inject(Bean obj) {
  2.         File file = new File("src/main/resources/data.properties");
  3.         Properties properties = new Properties();
  4.         try {
  5.             properties.load(new FileReader(file));
  6.         } catch (IOException e) {
  7.             throw new RuntimeException(e);
  8.         }
  9.         Field[] fields = obj.getClass().getDeclaredFields();
  10.         for (Field field : fields) {
  11.             field.setAccessible(true);
  12.             if (field.isAnnotationPresent(AutoInjectable.class) && field.getType() == FirstInterface.class) {
  13.                 try {
  14.                     Object someObject = null;
  15.                     try {
  16.                         Class<?> clazz = Class.forName(properties.getProperty("FirstInterface"));
  17.                         try {
  18.                             someObject = clazz.newInstance();
  19.                         } catch (InstantiationException e) {
  20.                             throw new RuntimeException(e);
  21.                         }
  22.                     } catch (ClassNotFoundException e) {
  23.                         throw new RuntimeException(e);
  24.                     }
  25.                     field.set(obj, someObject);
  26.                 } catch (IllegalAccessException e) {
  27.                     throw new RuntimeException(e);
  28.                 }
  29.             }
  30.             if (field.isAnnotationPresent(AutoInjectable.class) && field.getType() == SecondInterface.class) {
  31.                 try {
  32.                     Object someObject = null;
  33.                     try {
  34.                         Class<?> clazz = Class.forName(properties.getProperty("SecondInterface"));
  35.                         try {
  36.                             someObject = clazz.newInstance();
  37.                         } catch (InstantiationException e) {
  38.                             throw new RuntimeException(e);
  39.                         }
  40.                     } catch (ClassNotFoundException e) {
  41.                         throw new RuntimeException(e);
  42.                     }
  43.                     field.set(obj, someObject);
  44.                 } catch (IllegalAccessException e) {
  45.                     throw new RuntimeException(e);
  46.                 }
  47.             }
  48.         }
  49.         return obj;
  50.     }
Nov 25 '22 #1
0 6767

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Irmen de Jong | last post by:
What would be the best way, if any, to obtain the bytecode for a given loaded module? I can get the source: import inspect import os src = inspect.getsource(os) but there is no...
2
by: Jonathan LaRosa | last post by:
Hi all - I'm wondering if anyone has (or knows of) a tool that will allow me to search through VB code, tables, queries, reports, forms, and other objects, for references to all other types of...
2
by: **Developer** | last post by:
I've been asking about a Menu problem I have without results. So here is a test case I've developed that shows the problem. Simply create a soultion with one project containg one form and...
8
by: Wilbur Slice | last post by:
I need to write some VB.NET objects that can be called from another environment (a Progress app, specifically). I'm having some difficulty getting this to work. My first assumption was that I...
5
by: Doug Wright | last post by:
Hi The code in question is available from http://mozilla.pastebin.com/596645 Any help would be extremly appreciated, because I've spent many hours on trying to figure this out!!
0
by: ftech | last post by:
I am saving PDF files in SQL Server 2005 as an image and retrieve them back by their document ids. I use the following code: byte buffer = (byte)dtDoc.Rows; if(buffer != null) { ...
1
by: teddysnips | last post by:
I'm collaborating on a project with a colleague, sharing files through SourceSafe. So, I run GetLatestVersion and suddenly I have 264 build errors - all "Unexpected character" The file in...
1
by: Vbbeginner07 | last post by:
The follwing code is of a listview where i have to a to display the id and the name from a particular table ,empdetail. This is in the second form,dispalying id and name Private Sub Form_Load()...
2
by: Bongani Mgibi | last post by:
Hi guys please see attachment code, the code displays well with all browsers except with IE 8, if you guys can copy and paste then open it with IE then try opening it again using another browser you...
2
by: tmarynell | last post by:
I have created an SPC chart in Access. I need specific details of each data point wihtin the line graph to display when you hover over or double-click on the specific data point. It should include...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.