我不知道Firebase
和Arduino
....
但我写了这段代码,指的是David East的视频。
所以我收到了错误,请帮我解决。
错误是:
错误:(66,52)错误:找不到适合FirebaseListAdapter()的构造函数 构造函数FirebaseListAdapter.FirebaseListAdapter(Activity,Class,int,Firebase)不适用 (实际和正式的参数列表长度不同) 构造函数FirebaseListAdapter.FirebaseListAdapter(Activity,Class,int,Query)不适用 (实际和正式的参数列表长度不同)
这是MainActivity.java的代码:
package com.example.devashish.sprout;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.firebase.ui.FirebaseListAdapter;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
public class MainActivity extends AppCompatActivity {
Firebase mRootRef;
ArrayList<String> mMessages= new ArrayList<>();
TextView mTextView;
ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
protected void onStart(){
super.onStart();
mTextView=(TextView)findViewById(R.id.textViewCondition);
mListView=(ListView)findViewById(R.id.listView);
mRootRef = new Firebase("https://pleaserun.firebaseio.com");
Firebase messagesRef=mRootRef.child("condition");
final FirebaseListAdapter<String> adapter= new FirebaseListAdapter<String>() {
@Override
protected void populateView(View view, String s, int i) {
TextView textView=(TextView)view.findViewById(android.R.id.text1);
textView.setText(s);
mListView.setAdapter(adapter);
}
};
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我将您提到的行更改为:final FirebaseListAdapter adapter = new FirebaseListAdapter(this,String.class,android.R.layout.simple_list_item_1,messagesRef)
现在给出错误:错误:(71,38)错误:变量适配器可能尚未初始化
答案 0 :(得分:0)
您缺少FirebaseListAdapter
所需的构造函数参数。在你的情况下可能是这样的:
final FirebaseListAdapter<String> adapter= new FirebaseListAdapter<String>(
this, /* the activity */
String.class, /* the data type that you're reading from Firebase */
android.R.layout.two_line_list_item, /* the layout for each item */
messagesRef /* the Query/Firebase location to read the data from */
) {
...
请注意,在相关的documented in the FirebaseUI repo或Android Studio的错误消息中,这一切都非常合理FirebaseUI codelab。
答案 1 :(得分:0)
问题在于firebaseui依赖关系,请使用此
compile 'com.firebaseui:firebase-ui:0.3.1'
我有同样的问题,一旦我改变了错误就消失了。删除当前的firebaselistadapter代码并重新写入。祝你好运