2016-12-01 11 views
0

すべての文字列をstrings.xmlファイルに取得しようとしました。私はそれを実行しようとした場合 今、私はこれを取得:

public static final int fLat=0x7f060061; 

<resources> 
[...] 
<!-- Firebase Strings --> 
<string name="fLat">Flat</string> 
[...] 
</resources> 

Rファイルは、その文字列のためにこのエントリを持っています

E/AndroidRuntime: FATAL EXCEPTION: main 
       Process: de.hsd.ip2.wgapp, PID: 20467 
       android.content.res.Resources$NotFoundException: String resource ID #0x7f060061 
        at android.content.res.Resources.getText(Resources.java:321) 
        at android.content.res.Resources.getString(Resources.java:407) 
        at de.hsd.ip2.wgapp.Firebase.DatabaseContact.addRoom(DatabaseContact.java:215) 
        at de.hsd.ip2.wgapp.DialogfragmentCleaningSchedule$5.onDataChange(DialogfragmentCleaningSchedule.java:242) 
        at com.google.firebase.database.Query$1.onDataChange(Unknown Source) 
        at com.google.android.gms.internal.zzajp.zza(Unknown Source) 
        at com.google.android.gms.internal.zzakp.zzcxi(Unknown Source) 
        at com.google.android.gms.internal.zzaks$1.run(Unknown Source) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5294) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 

これが私のstrings.xmlです

とR.strings.fLatを右クリックして「用途を探す」を使用すると、属性値に適切なfLatが表示されます。

Attribute Value

ああ、私はそれを取得しようとする点は、私はまた、別の文字列を取得しようと1つは、私もフラットにフラットな名前を変更し、動作しますが、それだけでは動作しません。..

fReference.child(Resources.getSystem().getString(R.string.fLat)).child(Integer.toString(flatId)) 
      .child(Resources.getSystem().getString(R.string.cleaning)) 
      .child(title) 
      .setValue(r) 

私はあなたがResources.getSystem()を使用してリソースにアクセスcan't任意のアイデア:)

+0

'Resources.getSystem()'あなたのアプリケーションの 'Resources'ではありません。 –

答えて

1

を事前に

おかげ..問題なくR.string.cleaningを取得します。 APIで定義されているように:

に戻るだけのシステムリソースへのアクセスを提供し、グローバル共有リソースのオブジェクト(無アプリケーションリソース)

代わりにあなたが使用する必要があります

context.getResources().getString(R.string.fLat)のようなもの、

かあなたがアクティビティの中にいる場合:

getResources().getString(R.string.fLat)

だからあなたのコードがなければなりません:

fReference.child(getResources().getString(R.string.fLat)).child(Integer.toString(flatId)) 
      .child(getResources().getString(R.string.cleaning)) 
      .child(title) 
      .setValue(r) 
関連する問題