在类com.mahmoudradwan.e_news.Blog类上找不到mblogBegginer的设置器/字段,我已经在Blog类中定义了设置器,但是它给了我由Android Studio生成的错误设置器和获取器 尝试了所有在论坛中找到的答案 任何人都可以帮助我吗? 这是我的第二篇文章,因为我没有得到任何有帮助的回复
我的博客对象类
package com.mahmoudradwan.e_news;
/**
* Created by Mahmoud Radwan on 16/08/2018.
*/
public class Blog {
private static String mtitle;
private static String mblogBegginer;
private String mblogIntermediate;
private String mblogAdvanced;
private static String mImageurl;
private String mAudioBegginersurl;
private String mAudioIntermediateurl;
private String mAudioAdvancedurl;
public Blog() {
}
public static String getMtitle() {
return mtitle;
}
public static void setMtitle(String mtitle) {
Blog.mtitle = mtitle;
}
public static String getMblogBegginer() {
return mblogBegginer;
}
public static void setMblogBegginer(String mblogBegginer) {
Blog.mblogBegginer = mblogBegginer;
}
public String getMblogIntermediate() {
return mblogIntermediate;
}
public void setMblogIntermediate(String mblogIntermediate) {
this.mblogIntermediate = mblogIntermediate;
}
public String getMblogAdvanced() {
return mblogAdvanced;
}
public void setMblogAdvanced(String mblogAdvanced) {
this.mblogAdvanced = mblogAdvanced;
}
public static String getmImageurl() {
return mImageurl;
}
public static void setmImageurl(String mImageurl) {
Blog.mImageurl = mImageurl;
}
public String getmAudioBegginersurl() {
return mAudioBegginersurl;
}
public void setmAudioBegginersurl(String mAudioBegginersurl) {
this.mAudioBegginersurl = mAudioBegginersurl;
}
public String getmAudioIntermediateurl() {
return mAudioIntermediateurl;
}
public void setmAudioIntermediateurl(String mAudioIntermediateurl) {
this.mAudioIntermediateurl = mAudioIntermediateurl;
}
public String getmAudioAdvancedurl() {
return mAudioAdvancedurl;
}
public void setmAudioAdvancedurl(String mAudioAdvancedurl) {
this.mAudioAdvancedurl = mAudioAdvancedurl;
}
Blog(String mtitle, String mblogBegginer, String mblogIntermediate, String mblogAdvanced,
String mImageurl, String mAudioBegginersurl, String mAudioIntermediateurl, String mAudioAdvancedurl) {
this.mtitle = mtitle;
this.mblogBegginer = mblogBegginer;
this.mblogIntermediate = mblogIntermediate;
this.mblogAdvanced = mblogAdvanced;
this.mImageurl = mImageurl;
this.mAudioBegginersurl = mAudioBegginersurl;
this.mAudioIntermediateurl = mAudioIntermediateurl;
this.mAudioAdvancedurl = mAudioAdvancedurl;
}
}
文章探索类
package com.mahmoudradwan.e_news;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.ListView;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class ArticlesExplore extends AppCompatActivity {
FirebaseDatabase firebaseDatabase ;
DatabaseReference blogReference ;
ValueEventListener valueEventListener ;
ListView listView ;
RecyclerViewAdapter adapter ;
List<Blog> articles = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_articles_explore);
adapter = new RecyclerViewAdapter(this, R.layout.article_row, articles);
listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
firebaseDatabase = FirebaseDatabase.getInstance();
blogReference = firebaseDatabase.getReference().child("Article");
blogReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
Blog blog = dataSnapshot.getValue(Blog.class);
adapter.add(blog);
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
日志
08-20 15:08:06.597 5140-5140/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
08-20 15:08:07.483 5140-5140/com.mahmoudradwan.e_news V/FA: Registered activity lifecycle callback
08-20 15:08:07.519 5140-5140/com.mahmoudradwan.e_news D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
08-20 15:08:07.520 5140-5140/com.mahmoudradwan.e_news I/FirebaseInitProvider: FirebaseApp initialization successful
08-20 15:08:07.521 5140-5140/com.mahmoudradwan.e_news I/InstantRun: starting instant run server: is main process
08-20 15:08:07.598 5140-5162/com.mahmoudradwan.e_news V/FA: Collection enabled
08-20 15:08:07.598 5140-5162/com.mahmoudradwan.e_news V/FA: App package, google app id: com.mahmoudradwan.e_news, 1:765020936650:android:fd8001655cf26b78
08-20 15:08:07.599 5140-5162/com.mahmoudradwan.e_news I/FA: App measurement is starting up, version: 12780
08-20 15:08:07.599 5140-5162/com.mahmoudradwan.e_news I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
08-20 15:08:07.600 5140-5162/com.mahmoudradwan.e_news I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.mahmoudradwan.e_news
08-20 15:08:07.600 5140-5162/com.mahmoudradwan.e_news D/FA: Debug-level message logging enabled
08-20 15:08:07.686 5140-5162/com.mahmoudradwan.e_news I/zygote: IncrementDisableThreadFlip blocked for 5.170ms
08-20 15:08:07.701 5140-5140/com.mahmoudradwan.e_news V/FA: onActivityCreated
08-20 15:08:07.766 5140-5162/com.mahmoudradwan.e_news V/FA: Connecting to remote service
08-20 15:08:07.841 5140-5162/com.mahmoudradwan.e_news V/FA: Connection attempt already in progress
08-20 15:08:08.075 5140-5162/com.mahmoudradwan.e_news I/FA: Tag Manager is not found and thus will not be used
08-20 15:08:08.088 5140-5162/com.mahmoudradwan.e_news D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=3366437205721944027}]
08-20 15:08:08.095 5140-5167/com.mahmoudradwan.e_news D/OpenGLRenderer: HWUI GL Pipeline
08-20 15:08:08.158 5140-5162/com.mahmoudradwan.e_news V/FA: Connection attempt already in progress
08-20 15:08:08.158 5140-5162/com.mahmoudradwan.e_news V/FA: Connection attempt already in progress
08-20 15:08:08.163 5140-5162/com.mahmoudradwan.e_news V/FA: Activity resumed, time: 5862461
08-20 15:08:08.226 5140-5167/com.mahmoudradwan.e_news I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
08-20 15:08:08.227 5140-5167/com.mahmoudradwan.e_news I/OpenGLRenderer: Initialized EGL, version 1.4
08-20 15:08:08.227 5140-5167/com.mahmoudradwan.e_news D/OpenGLRenderer: Swap behavior 1
08-20 15:08:08.230 5140-5167/com.mahmoudradwan.e_news W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
08-20 15:08:08.230 5140-5167/com.mahmoudradwan.e_news D/OpenGLRenderer: Swap behavior 0
08-20 15:08:08.250 5140-5167/com.mahmoudradwan.e_news D/EGL_emulation: eglCreateContext: 0xf19aff60: maj 2 min 0 rcv 2
08-20 15:08:08.284 5140-5167/com.mahmoudradwan.e_news D/EGL_emulation: eglMakeCurrent: 0xf19aff60: ver 2 0 (tinfo 0xf199b8a0)
08-20 15:08:08.445 5140-5167/com.mahmoudradwan.e_news D/EGL_emulation: eglMakeCurrent: 0xf19aff60: ver 2 0 (tinfo 0xf199b8a0)
08-20 15:08:08.640 5140-5162/com.mahmoudradwan.e_news D/FA: Connected to remote service
08-20 15:08:08.643 5140-5162/com.mahmoudradwan.e_news V/FA: Processing queued up service tasks: 4
08-20 15:08:14.009 5140-5162/com.mahmoudradwan.e_news V/FA: Inactivity, disconnecting from the service
08-20 15:08:27.008 5140-5162/com.mahmoudradwan.e_news V/FA: Recording user engagement, ms: 18944
08-20 15:08:27.011 5140-5162/com.mahmoudradwan.e_news V/FA: Connecting to remote service
08-20 15:08:27.019 5140-5162/com.mahmoudradwan.e_news V/FA: Activity paused, time: 5881404
08-20 15:08:27.027 5140-5162/com.mahmoudradwan.e_news D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=18944, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=3366437205721944027}]
08-20 15:08:27.048 5140-5140/com.mahmoudradwan.e_news V/FA: onActivityCreated
08-20 15:08:27.175 5140-5162/com.mahmoudradwan.e_news V/FA: Connection attempt already in progress
08-20 15:08:27.187 5140-5162/com.mahmoudradwan.e_news D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=MainActivity, firebase_previous_id(_pi)=3366437205721944027, firebase_screen_class(_sc)=ArticlesExplore, firebase_screen_id(_si)=3366437205721944028}]
08-20 15:08:27.201 5140-5176/com.mahmoudradwan.e_news W/zygote: Unsupported class loader
08-20 15:08:27.224 5140-5176/com.mahmoudradwan.e_news W/zygote: Skipping duplicate class check due to unsupported classloader
08-20 15:08:27.236 5140-5176/com.mahmoudradwan.e_news I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
08-20 15:08:27.236 5140-5176/com.mahmoudradwan.e_news I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 6
08-20 15:08:27.293 5140-5162/com.mahmoudradwan.e_news V/FA: Connection attempt already in progress
08-20 15:08:27.293 5140-5162/com.mahmoudradwan.e_news V/FA: Connection attempt already in progress
08-20 15:08:27.294 5140-5162/com.mahmoudradwan.e_news V/FA: Activity resumed, time: 5881552
08-20 15:08:27.300 5140-5167/com.mahmoudradwan.e_news D/EGL_emulation: eglMakeCurrent: 0xf19aff60: ver 2 0 (tinfo 0xf199b8a0)
08-20 15:08:27.331 5140-5176/com.mahmoudradwan.e_news W/zygote: Unsupported class loader
08-20 15:08:27.332 5140-5176/com.mahmoudradwan.e_news W/zygote: Skipping duplicate class check due to unsupported classloader
08-20 15:08:27.352 5140-5167/com.mahmoudradwan.e_news D/EGL_emulation: eglMakeCurrent: 0xf19aff60: ver 2 0 (tinfo 0xf199b8a0)
08-20 15:08:27.362 5140-5162/com.mahmoudradwan.e_news D/FA: Connected to remote service
08-20 15:08:27.365 5140-5162/com.mahmoudradwan.e_news V/FA: Processing queued up service tasks: 4
08-20 15:08:27.386 5140-5167/com.mahmoudradwan.e_news D/EGL_emulation: eglMakeCurrent: 0xf19aff60: ver 2 0 (tinfo 0xf199b8a0)
08-20 15:08:27.499 5140-5178/com.mahmoudradwan.e_news D/NetworkSecurityConfig: No Network Security Config specified, using platform default
08-20 15:08:28.848 5140-5145/com.mahmoudradwan.e_news I/zygote: Do partial code cache collection, code=26KB, data=30KB
08-20 15:08:28.849 5140-5145/com.mahmoudradwan.e_news I/zygote: After code cache collection, code=26KB, data=30KB
08-20 15:08:28.849 5140-5145/com.mahmoudradwan.e_news I/zygote: Increasing code cache capacity to 128KB
08-20 15:08:32.509 5140-5162/com.mahmoudradwan.e_news V/FA: Inactivity, disconnecting from the service
08-20 15:08:38.279 5140-5140/com.mahmoudradwan.e_news W/ClassMapper: No setter/field for mImageurl found on class com.mahmoudradwan.e_news.Blog
08-20 15:08:38.280 5140-5140/com.mahmoudradwan.e_news W/ClassMapper: No setter/field for mblogBegginer found on class com.mahmoudradwan.e_news.Blog
08-20 15:08:38.280 5140-5140/com.mahmoudradwan.e_news W/ClassMapper: No setter/field for mtitle found on class com.mahmoudradwan.e_news.Blog
08-20 15:08:38.318 5140-5140/com.mahmoudradwan.e_news W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
08-20 15:08:38.402 5140-5140/com.mahmoudradwan.e_news W/Glide: Load failed for null with size [0x0]
class com.bumptech.glide.load.engine.GlideException: Received null model
08-20 15:08:38.420 5140-5140/com.mahmoudradwan.e_news W/Glide: Load failed for null with size [0x0]
class com.bumptech.glide.load.engine.GlideException: Received null model
Firebase dataBase Example
{
"-LKIJ4U5ymhgXyt7A4C2" : {
"mAudioAdvancedurl" : "com.google.android.gms.tasks.zzu@9f1c1e4",
"mAudioBegginersurl" : "com.google.android.gms.tasks.zzu@c28a776",
"mAudioIntermediateurl" : "com.google.android.gms.tasks.zzu@b997177",
"mImageurl" : "com.google.android.gms.tasks.zzu@2810a11",
"mblogAdvanced" : "null now",
"mblogBegginer" : "Hello we test desc yarb t4t8l rbna ystrha",
"mblogIntermediate" : "null now",
"mtitle" : "Hello it's a test version title Hi hi ."
}
}
答案 0 :(得分:0)
步骤1:从Blog类中删除所有static
关键字(甚至在方法名称删除它之前)。 static info
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
.....
//listView.setAdapter(adapter); remove this line from here
.......
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
Blog blog = dataSnapshot.getValue(Blog.class);//also make sure this line is returning a valid result which can be cast to Blog Class
adapter.add(blog);
//listView.setAdapter(adapter); or you can call here but not good approach
}
.................
});
listView.setAdapter(adapter); // call it here
}
}