2016-11-21 2 views
-3
public HashMap<String, double[][]> GradientDescent(double[][] ratingData_norm, double[][] ratingData_binary, double[][] theta, double[][] X, int iter, double alpha, double lambda) 

    { 
     HashMap<String, double[][]> result= new HashMap<String, double[][]>(); 

     double[][] theta_tran=new *double[theta[0].length][theta.length]();* 
     double[][] theta_grad=new *double[theta.length][theta[0].length]();* 
------- 
--- 
-- 
--} 

2D 이중 배열 선언에 오류가 발생합니다. 유형 불일치 오류입니다. double [] [] [] [] [] double을 변환 할 수 없습니까? 내가 잘못 이해하고 어떻게 해결할 수 있는지 누가 친절하게 말해 줄 수 있습니까?Java, 2D 배열 선언의 유형 불일치 오류

미리 감사드립니다. !!!!

답변

1

게시 한 코드가 수정되어 컴파일하려고 할 수 있습니다.

import java.util.*; 

public class Test { 

    public HashMap<String, double[][]> GradientDescent(double[][] ratingData_norm, double[][] ratingData_binary, double[][] theta, double[][] X, int iter, double alpha, double lambda) 
    { 
     HashMap<String, double[][]> result= new HashMap<String, double[][]>(); 

     double[][] theta_tran=new double[theta[0].length][theta.length](); 
     double[][] theta_grad=new double[theta.length][theta[0].length](); 
    } 

} 

그때 나는 그것을 컴파일 : 당신이 질문을 다음 시간 동안
> javac -d . Test.java 
Test.java:9: error: ';' expected 
     double[][] theta_tran=new double[theta[0].length][theta.length](); 
                    ^
Test.java:10: error: ';' expected 
     double[][] theta_grad=new double[theta.length][theta[0].length](); 
                    ^
2 errors 

, 당신은 컴파일 할 준비가 코드의 최소한의 금액을 게시해야하고, 문제를 입증 할 수 있습니다.

문제가있는 곳을 나타 내기 위해 이상한 방법으로 코드를 수정해서는 안됩니다. 그 별표가 실제 코드의 일부인지 여부는 알 수 없습니다. 뭔가를 추가해야하는 경우 댓글을 사용하십시오.

그리고 받고있는 오류 메시지가 포함되어 있어야합니다. 오류 메시지는 당신이 뭘 잘못하고 있는지 분명히했습니다.

컴파일 할 수 있습니다

import java.util.*; 

public class Test { 

    public HashMap<String, double[][]> GradientDescent(double[][] ratingData_norm, double[][] ratingData_binary, double[][] theta, double[][] X, int iter, double alpha, double lambda) 
    { 
     HashMap<String, double[][]> result= new HashMap<String, double[][]>(); 

     // No brackets needed for array instantiation 
     double[][] theta_tran=new double[theta[0].length][theta.length]; 
     double[][] theta_grad=new double[theta.length][theta[0].length]; 

     return null; 
    } 

} 

그리고 그 모든에서 설명한 오류 아니다. 형식이 실제로 일치하지 않으면 게시 한 코드의 어느 부분에도 없습니다.

+0

감사합니다. –