Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7899481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:42:50+00:00 2026-06-03T08:42:50+00:00

Given class Value : public class Value { private int xVal1; private int xVal2;

  • 0

Given class Value :

public class Value {

    private int xVal1;
    private int xVal2; 
    private double pVal;


    // constructor of the Value class 

    public Value(int _xVal1 ,int _xVal2 , double _pVal)
    {
        this.xVal1 = _xVal1;
        this.xVal2 = _xVal2;
        this.pVal = _pVal;
    }

    public int getX1val()
    {
        return this.xVal1;
    }


...
}

I’m trying to create a new instance of that class using reflection :

from Main :

    .... // some code 
    ....
    ....
    int _xval1 = Integer.parseInt(getCharacterDataFromElement(line));
    int _xval2 = Integer.parseInt(getCharacterDataFromElement(line2));
    double _pval = Double.parseDouble(getCharacterDataFromElement(line3));

     Class c = null;
     c = Class.forName("Value");
     Object o = c.newInstance(_xval1,_xval2,_pval);

...

This doesn’t work , Eclipse’s output : The method newInstance() in the type Class is not applicable for the arguments (int, int, double)

If so , how can I create a new Value object using reflection , where I invoke the Constructor of Value ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:42:51+00:00Added an answer on June 3, 2026 at 8:42 am

    You need to locate the exact constructor for this. Class.newInstance() can only be used to call the nullary constructor. So write

    final Value v = Value.class.getConstructor(
       int.class, int.class, double.class).newInstance(_xval1,_xval2,_pval);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this class: class C { private: struct Foo { int key1, key2, value;
Given the following class: class MyClass { public: int value() const { return value_;
Given class Round: public class Round { private int roundNumber; private Door door1; private
Given: class example { public: std::vector<std::vector<int>> a; int b; } func() { example e;
Say you have the following class public class AccessStatistics { private final int noPages,
i need Enumarable value from below class but give error public static Enumerable LoadDataByName(string
I have a class C(Of T). I want to determine if some given value
Given the following: CriteriaQuery<SomeDTO> cQuery; CriteriaBuilder cb; Root<SomeClass> r; ... cQuery.select(cb.construct(SomeDTO.class, FIXED VALUE, r.get(SomeClass_.someValue)
Given: class StringRecord : INotifyPropertyChanged { public string Key { get; set; } //
Given class Award : public class Award { /* * */ // fields of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.