2012-12-14 40 views
0

我想獲得一個簡單的renderscript函數來取兩個numnbers,添加它們並返回結果,但是我還沒有設法找到一個可以順利執行的示例項目。 我不斷收到一個奇怪的錯誤,當我嘗試加載該文件:無法獲得簡單的renderscript數學運算功能

ScriptC_myexamplescript myScript; 
RenderScript rs = RenderScript.create(this); 

我得到的錯誤:

Symbol not found: .rs.dtor on the next line: 
myScript = new ScriptC_myexamplescript(rs, getResources(), R.raw.myexamplescript); 

我.RS文件只是一些簡單:

#pragma version(1) 
#pragma rs java_package_name(com.exercise.<my pacakge name>); 

void init(){ 

} 

void root(const float *v_in, float *v_out) { 

    const float *data = v_in; 
    float *outData = v_out; 
    *outData = *data;  

} 

有誰知道這意味着什麼,或者如果有一個簡單的項目,我可以下載Android ICS和後來做數學,而不是實際的渲染,只是工作?

(我可以得到一個渲染腳本文件的工作,但是這不是我想要的。我不希望在任何圖形)

編輯 今天,我試圖使它運行,得到以下問題:

Allocation mInAllocation = null; 
Allocation mOutAllocation; 

float[] A = new float[1]; 
for (int i = 0; i < 1; i++) { 
A[i] = 2; 
} 



Allocation inFloatPointer = Allocation.createSized(rs, Element.F32(rs), A.length, Allocation.USAGE_SCRIPT); 
Allocation outFloatPointer = Allocation.createSized(rs, Element.F32(rs), A.length, Allocation.USAGE_SCRIPT); 
inFloatPointer.copyFrom(A); // copies from an array of floats (random numbers in this test case). 
mScript.forEach_root(inFloatPointer, outFloatPointer);    

我得到的錯誤信息: forEach_root是undedifed類型ScriptC_RenderScript 有一個在java文件沒有功能forEach_root甚至後我清理項目,它仍然是不存在的方法。

有沒有一個簡單的項目,我可以下載只有一個數學函數,我可以下載?

回答

1

您確定這裏確實存在錯誤嗎?我相信你只是看到額外的詳細日誌信息。你能發佈確切的logcat(或Java異常跟蹤)嗎?請注意,如果你真的想執行你的函數,你需要創建一個輸入和輸出分配,然後調用「myScript.forEach_root(input,output);」以便讓它在每個輸入/輸出單元上執行root()函數。完成後,您可以從輸出分配中讀取結果並從Java中使用它們。

+0

後提到的錯誤是出現了錯誤,但是今天我甚至不能得到它當我將forEach_root函數放入時,就像上面提到的那樣編譯。你能指出一個剛剛起作用的示例項目嗎?我認爲這將是最簡單的。 –

+1

您可能會看到Java缺少forEach_root()錯誤,因爲您的目標是早期的API(未反映forEach的Java版本)。嘗試使用更高的目標API(至少ICS)。 SDK包含一個示例HelloCompute基準。我也可以將您指向AOSP資源(http://source.android.com/source/downloading.html)。在AOSP中,您可以在frameworks/base/tests/RenderScriptTests /中查看一些我們用於測試的應用程序。該目錄中的最佳示例可能是ImageProcessing。 –

+0

謝謝。更改API無法正常工作,但是我將手機更新至JB 4.2,現在hellocompute示例適用於數學函數。我不知道是什麼導致了這個問題,但現在已經消失了。 –

0

添加到清單,<application>之前,該行

<uses-sdk android:minSdkVersion="14" /> 

14歲以下的任何值拋出你ant clean debug