The answer is quite simple, Richard. God inspired Paul the Apostle and James to write about justification using the SAME CHARACTER in the Bible: Abraham. It is from this perspective that the apparent "contradiction" is easily resolved.
Let us see what Romans 4 says on this:
Romans 4:1-5
1 What shall we say then that Abraham our father, as pertaining to the flesh, hath found?
2 For if Abraham were justified by works, he hath whereof to glory; but not before God.
3 For what saith the scripture? Abraham believed God, and it was counted unto him for righteousness.
4 Now to him that worketh is the reward not reckoned of grace, but of debt.
5 But to him that worketh not, but believeth on him that justifieth the ungodly, his faith is counted for righteousness.
Abraham was justified by the same means that any of us can be justified:
Ephesians 2:8-10
8 For by grace are ye saved through faith; and that not of yourselves: it is the gift of God:
9 Not of works, lest any man should boast.
10 For we are his workmanship, created in Christ Jesus unto good works, which God hath before ordained that we should walk in them.
Yet the Bible does not define "faith" as a mere mental assent, but as a full-heart surrender that will be revealed in a transformed life and character:
James 2:17-24
17 Even so faith, if it hath not works, is dead, being alone.
18 Yea, a man may say, Thou hast faith, and I have works: shew me thy faith without thy works, and I will shew thee my faith by my works.
19 Thou believest that there is one God; thou doest well: the devils also believe, and tremble.
20 But wilt thou know, O vain man, that faith without works is dead?
21 Was not Abraham our father justified by works, when he had offered Isaac his son upon the altar?
22 Seest thou how faith wrought with his works, and by works was faith made perfect?
23 And the scripture was fulfilled which saith, Abraham believed God, and it was imputed unto him for righteousness: and he was called the Friend of God.
24 Ye see then how that by works a man is justified, and not by faith only.
Given that Abraham is used to express righteousness by faith in Romans 4 and then he is further described as having "faith that wrought with his works" (James 2:22), it becomes clear that we need to understand what "faith" really is when the Bible uses it. There is a type of faith which is an assent to the existence of something--like how the devils believe God exists, but tremble. That is not saving faith. Saving faith is a transaction in which we enter into covenant relation with God, and His grace transforms the heart and mind, and the works of righteousness wrought in the life are the manifestation of the indwelling of the Holy Spirit. If a person says they have faith but there is no evidence of that faith in the works of their life, it is not genuine faith--it becomes clear that the grace of God has not wrought a transformation of character. What are the sure works (or fruits) that show that "faith" is genuine in the life?
Galatians 5:22-23
22 But the fruit of the Spirit is love, joy, peace, longsuffering, gentleness, goodness, faith,
23 Meekness, temperance: against such there is no law.
All of these fruits will be seen in the life without one missing when the soul is living by faith upon the Son of God. Abraham obeyed God because he loved Him, and his obedience to offer up Isaac was the demonstration of a living faith active in love, even as Paul described it as "faith which worketh by love" (Galatians 5:6). A faith that does not work is not actually saving faith! It is as simple as that!