0

firebaseデータベースのすべてのアイテムが必要なので、私はこのアイテムを取り込むためにrecyclerviewを使用しました。 recylerviewのアクティビティが呼び出されると、アプリケーションがクラッシュして致命的なエラーが発生します。Firebaseベースのリサイクルビュー - Firebaseを使用する前にFirebase.setAndroidContext()を使用してAndroidコンテキストを設定する必要があります

これは私のコード私は間違っランタイム

E/AndroidRuntime: FATAL EXCEPTION: main 
       Process: com.example.zuke.zukevalet, PID: 9243 
       java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.zuke.zukevalet/com.example.zuke.zukevalet.RequestPendingActivity}: java.lang.RuntimeException: You need to set the Android context using Firebase.setAndroidContext() before using Firebase. 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2548) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6077) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
       Caused by: java.lang.RuntimeException: You need to set the Android context using Firebase.setAndroidContext() before using Firebase. 
        at com.firebase.client.core.Context.getPlatform(Context.java:45) 
        at com.firebase.client.core.Context.ensureLogger(Context.java:218) 
        at com.firebase.client.core.Context.initServices(Context.java:105) 
        at com.firebase.client.core.Context.freeze(Context.java:92) 
        at com.firebase.client.core.RepoManager.getLocalRepo(RepoManager.java:55) 
        at com.firebase.client.core.RepoManager.getRepo(RepoManager.java:19) 
        at com.firebase.client.Firebase.<init>(Firebase.java:172) 
        at com.firebase.client.Firebase.<init>(Firebase.java:177) 
        at com.firebase.client.Firebase.<init>(Firebase.java:155) 
        at com.example.zuke.zukevalet.RequestPendingActivity.<init>(RequestPendingActivity.java:21) 
        at java.lang.Class.newInstance(Native Method) 
        at android.app.Instrumentation.newActivity(Instrumentation.java:1078) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2538) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)  
        at android.app.ActivityThread.-wrap12(ActivityThread.java)  
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)  
        at android.os.Handler.dispatchMessage(Handler.java:102)  
        at android.os.Looper.loop(Looper.java:154)  
        at android.app.ActivityThread.main(ActivityThread.java:6077)  
        at java.lang.reflect.Method.invoke(Native Method)  
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)  
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)  
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found. 

私のjavaファイル

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.support.v7.widget.LinearLayoutManager; 
import android.support.v7.widget.RecyclerView; 
import android.view.View; 
import android.widget.ListView; 
import android.widget.TextView; 

import com.firebase.client.Firebase; 
import com.firebase.geofire.GeoFire; 
import com.firebase.ui.FirebaseListAdapter; 
import com.firebase.ui.FirebaseRecyclerAdapter; 
import com.google.firebase.database.DatabaseReference; 
import com.google.firebase.database.FirebaseDatabase; 

public class RequestPendingActivity extends AppCompatActivity { 

RecyclerView RequestListView; 
Firebase ref = new Firebase("https://simplyparc.firebaseio.com/Valet Requests Location"); 
private DatabaseReference mDatabase; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_request_pending); 
    RequestListView = (RecyclerView) findViewById(R.id.RequestListView); 
    RequestListView.setHasFixedSize(true); 
    RequestListView.setLayoutManager(new LinearLayoutManager(this)); 


    GeoFire geoFire = new GeoFire(mDatabase); 


} 

@Override 
protected void onStart(){ 
    super.onStart(); 
    FirebaseRecyclerAdapter<String, MessageViewHolder> adapter = new FirebaseRecyclerAdapter<String, MessageViewHolder>(String.class, android.R.layout.two_line_list_item, MessageViewHolder.class, ref) { 
     @Override 
     protected void populateViewHolder(MessageViewHolder messageViewHolder, String s, int i) { 
      messageViewHolder.mText.setText(s); 
     } 
    }; 
    RequestListView.setAdapter(adapter); 

} 

public static class MessageViewHolder extends RecyclerView.ViewHolder{ 
    TextView mText; 

    public MessageViewHolder(View v){ 
     super(v); 
     mText = (TextView) v.findViewById(android.R.id.text1); 
    } 
} 

} 

マイアンドロイドマニフェストファイル

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".FirstActivity" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:screenOrientation="portrait"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".PendingSelectorActivity" 
     android:label="Select Pending task" 
     android:screenOrientation="portrait"/> 
    <activity 
     android:name=".RequestPendingActivity" 
     android:label="Pending Request" 
     android:screenOrientation="portrait"/> 
    <!-- 
     The API key for Google Maps-based APIs is defined as a string resource. 
     (See the file "res/values/google_maps_api.xml"). 
     Note that the API key is linked to the encryption key used to sign the APK. 
     You need a different API key for each encryption key, including the release key that is used to 
     sign the APK for publishing. 
     You can define the keys for the debug and release targets in src/debug/ and src/release/. 
    --> 
    <meta-data 
     android:name="com.google.android.geo.API_KEY" 
     android:value="@string/google_maps_key"/> 

    <activity 
     android:name=".RequestAcceptMapActivity" 
     android:label="@string/title_activity_request_accept_map" 
     android:screenOrientation="portrait"/> 
    <activity 
     android:name=".DropOffActivity" 
     android:label="Drop-Off Request" 
     android:screenOrientation="portrait"/> 


</application> 

致命的なエラーが発生しているのですか?

答えて

4

それは例外メッセージである:あなたがFirebase


Where to put Firebase.setAndroidContext() functionを使用する前に、Firebase.setAndroidContext()を使用してAndroidのコンテキストを設定する必要が

見積もる(のステップ4)Firebase quickstart documentation

Firebaseライブラリは、Android Contextで一度初期化する必要があります。これは、Firebaseリファレンスが作成される前に発生する必要があります。 または使用してください。

MyApplication.javaを作成します。

public class MyApplication extends android.app.Application { 

    @Override 
    public void onCreate() { 
     super.onCreate(); 
     Firebase.setAndroidContext(this); 
    } 
} 

そして、あなたのAndroidManifest.xml名前パラメータ値を更新します。

<application 
     android:label="@string/app_name" 
     android:name=".MyApplication"> 
... 
</application> 
関連する問題