2014-05-21 2 views
0

그래서 여기에 모든 Java 전문가에게 제 질문이 있습니다. 속성 파일에서 다른 클래스로 쿼리를 가져 오는 문자열을 전달하려고합니다. 이것이 정말로 기본적인 것 같아서 미안해 ... 나는 정말로 그것을 어떻게하는지 모른다. 여기에 지금까지 여기 문자열을 다른 클래스에 쿼리로 전달

public class CrunchifyGetPropertyValues { 

    public String getPropValues() throws IOException { 

     //some code... 

     // get the property value and print it out 
     String user = prop.getProperty("user"); 
     String startDate = prop.getProperty("startDate"); 
     String endDate = prop.getProperty("endDate"); 
     String values = prop.getProperty("values"); 

     result = "stuff = " + startDate + ", " + endDate + ", " + values; 
     System.out.println(result + "\nProgram Ran on " + time + " by user=" + user); 
     return result; 
    } 

    //this is the code that i thought i needed to connect the strings 
    executeDataQuery startConv = new executeDataQuery(); 
    startConv.executeDataQuery(startDate); 
} 

내가

private static GaData executeDataQuery(Analytics analytics, String profileId, String newValueData) throws IOException { 
    return analytics.data().ga().get("ga:" + profileId, // Table Id. ga: + profile id. 
     newValue Data, // Start date: here is where i want to import the strings into 
     "2014-05-20", // End date. 
     "ga:pageviews,ga:sessions,ga:uniquePageviews") // Metrics. 
     .setDimensions("ga:date") 
     .setSort("-ga:date") 
     .setMaxResults(25) 
     .execute(); 
} 

편집에 문자열을 넣어하려고 내 쿼리가 가지고 무엇을 : 그래서 내가 주위에 몇 가지 물건을 변경했지만 내 코드는 갔다 여기에 새로운 오류 나 ... 난 문자열 새로운 StringValue = getPropValues ​​()에 넣어

try { 
    httpTransport = GoogleNetHttpTransport.newTrustedTransport(); 
    dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR); 
    Analytics analytics = initializeAnalytics(); 
    String profileId = getFirstProfileId(analytics); 
    String newStringValue = getPropValues(); 
    if (profileId == null) { 
    System.err.println("No profiles found."); 
    } else { 
    GaData gaData = executeDataQuery(analytics, profileId, newStringValue); 
    printGaData(gaData); 
    } 
//lots of other code 

은 ...이 방법은 ... 어떤 도움을 정의 할 수 없음을 말한다?

+0

'System.out.println (myString);'이라고 말하면 문자열을 다른 클래스에 전달합니다. 귀하의 상황에 특별히 특별한 것은 무엇입니까? –

답변

0

서명 (두 번째 방법의 '머리') 정도 : private static GaData executeDataQuery(Analytics analytics, String profileId, String newStringValue) throws IOException { 그리고 거기에 newStringValue을 사용하십시오.

첫 번째 코드에서 executeDataQuery(first, second, newStringValue)으로 전화하십시오.

+0

좋아요. 추가 문자열을 호출하기 위해 executeDataQuery의 서명을 변경했는데, 다른 곳으로 데려갔습니다. 다른 곳에서 데이터를 바꿀 필요가 있습니다. – zomdar

+0

대부분의 경우 컴파일러에 'executeDataQuery' 세 가지 매개 변수를 취합니다. 방법의 서명도 변경 했습니까? 이 경우 컴파일러는 메소드를 찾아야한다. –

관련 문제