2017-06-08 41 views
0

我開發了一個項目,原生反應0.43.3android.widget.imageview不能轉換爲android.view.viewgroup(僅限搭載Android,IOS是OK)

我犯了一個錯誤發展,只有測試所有項目在iOS中。 (工作正常那裏)

的問題是,當我試圖生成APK上傳到Play商店中,並在設備的測試,我發現了錯誤:

android.widget.imageview不能轉換爲android.view .viewgroup

我的主要問題是關於如何顯示錯誤。在死亡的紅色屏幕上,我不知道如何找到線路和組件在原生反應中發生錯誤。我想也許我不能意識到,因爲JavaScript代碼已經編譯。

無論如何,我不知道如何解決這個問題。

我想也許是因爲我用紡紗內部的圖像(顯示圖像被加載),是這樣的:

<View style={[styles.resourceActions]}> 
     <Image 
     style={{width: imgWidth, height: imgHeight}} 
     source={{uri: this.props.imageUrl}} 
     onLoad = {() => this.setState({ loading: false })} 
     > 
     <ActivityIndicator 
      animating={this.state.loading} 
      style={[styles.spinner, styles.centering, {marginTop: this.state.loadingMarginTop}]} 
      size="large" 
     /> 
     </Image> 
    </View> 

但我不知道,因爲我使用的ImageView(和fastimage成分)大量的配件和意見

我的依賴關係:

"@remobile/react-native-refresh-infinite-listview": "^1.0.6", 
"react": "16.0.0-alpha.6", 
"react-native": "0.43.3", 
"react-native-camera": "git+https://github.com/lwansbrough/react-native-camera.git", 
"react-native-device-info": "^0.10.2", 
"react-native-fast-image": "0.0.9", 
"react-native-google-analytics-bridge": "^5.0.1", 
"react-native-htmlview": "^0.9.0", 
"react-native-loading-spinner-overlay": "^0.4.4", 
"react-native-material-design": "^0.3.7", 
"react-native-modalbox": "^1.3.9", 
"react-native-photo-view": "^1.2.0", 
"react-native-qrcode-scanner": "0.0.11", 
"react-native-qrcode-svg": "^5.0.0", 
"react-native-radio-buttons": "^0.14.0", 
"react-native-router-flux": "3.38.0", 
"react-native-share": "^1.0.20", 
"react-native-side-menu": "^0.20.1", 
"react-native-svg": "^5.1.7", 
"react-native-vector-icons": "^4.0.1" 

感謝任何方位在我的問題

回答

1

原生Android也,我們不能投ImageViewViewGroup作爲ImageView不擴展類ViewGroup。實際上,這種鑄造是不可能的。

+0

什麼「投」在這種情況下意味着什麼?是我在做''?或當我做''?我應該如何解決這個問題?對不起,在同一句話中有這麼多問題,但是因爲我想了解所有人認爲我不知道,非常感謝 –

0

鑄造(在此情況下向下轉換)

爲簡單起見正在一個特定類型的對象和「把它變成」,其從所述第一繼承另一個對象類型。 在編譯時並不在運行時檢查Casting。 基本上你說的是編譯器'相信我,你可以把這個對象看作是這種類型的'。

例子:

Object aSentenceObject = "This is just a regular sentence"; 
String aSentenceString = (String) aSentenceObject; 

現在..還記得,當我說我把它在運行時檢查?那麼如果鑄造不能完成會發生什麼? 讓我們在這種情況下,說:

Object aSentenceObject = "This is just a regular sentence"; 
int aSentenceString = (int) aSentenceObject; 

由於aSentenceObject不能被鑄造爲int的異常將被拋出。這樣

ClassCastException: java.lang.Object cannot be cast to java.lang.Integer 

但是,這是什麼都事做你的情況?

"With React Native, you don't build a 「mobile web app」, an 「HTML5 app」, or a 「hybrid app」. You build a real mobile app that's indistinguishable from an app built using Objective-C or Java. React Native uses the same fundamental UI building blocks as regular iOS and Android apps."

因爲它在官方說在某些時候你的JavaScript代碼莫名其妙編譯爲母語陣營本地頁面(在Android的情況下,使用Java)。

We can see that each React Native control will interact with a native counterpart component . "We are ‘allowed’ to write JavaScript because React Native presents us with a control which is written in JavaScript. But this is always underpinned by the phones actual native counterpart. React Native simply allows the bridge for the two way communication to happen" As it is explained in this article

在原生Android,圖片不能生育(如滾動型或ViewGroup中那樣) 所以在翻譯您的JS代碼到Java的「翻譯機」的這個過程中儘量把你的圖片作爲ViewGroup中,因爲它有孩子。 結果就是你

android.widget.imageview cannot be cast to android.view.viewgroup 

結論

如果刪除嵌套結構和放置ActivityIndi​​cator組件作爲圖像組件應該固定的兄弟

相關問題