Jul 6, 2008

Can't Assign Value

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

free web hosting

Can't Assign Value

kvarnerexpress
First of all, bear with me. Only on my 3rd week of java programming, so stupid error will occuor

Lets start with the code in question:

Code:

CODE
public Matrix multiplyMatrix(Matrix B)
   {
       if(coln != B.returnRowlength())
       {
       Matrix local = new Matrix(rows, B.returnColnlength());
       int value = 0;
           for(int i = 0; i < rows; i++) // Controls row count
           {
               for(int j = 0; j < B.returnColnlength(); j++) // Control coln count
               {
                   for(int k = 0; k < coln; k++)
                   {
                       value = value + (array[i][k] * B.returnValue(k,j));
                    local[i][j] = value;
                   }
               }
           }
           return local;
       }
       else
       {
             System.out.print("Dimension does not match. Multiplay function cannot be executed.");
       }
   }


The problem is within the: local[i][j] = value;
I get this error message: array required, But matrix found
local is an array, so why does it say array required?

Thanks,kvarnerexpress

 

 

 


Reply

beeseven
APCS in Java? I'm in that class, too... and we just got that problem today. I haven't finished it but basically your problem is that local is an object, not an array. Arrays are special, so they can be accessed using []'s, but objects can't. What I did for that part was to make local a two dimensional array (int[][] local = new int[number of rows in a][number of cols in b]) and a constructor for the Matrix class that took a two dimensional array argument:
CODE
int[][] data;
public Matrix(int[][] a)
{
  data = a;
}
Then at then end I put "return new Matrix(local)"

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:


Searching Video's for assign
advertisement



Can't Assign Value



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE