Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android studio bug,通过添加Log.d修复?_Android_Logging_Service_Android Widget_Realm - Fatal编程技术网

Android studio bug,通过添加Log.d修复?

Android studio bug,通过添加Log.d修复?,android,logging,service,android-widget,realm,Android,Logging,Service,Android Widget,Realm,我知道这听起来很疯狂,也很愚蠢,但我现在测试了20次,对此我没有其他解释,也许我做错了什么,或者我不知道 好的,我正在创建一个小部件,它使用领域数据库从中加载数据。我在应用程序级别声明了领域默认配置: public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); Realm.init(this); Realm

我知道这听起来很疯狂,也很愚蠢,但我现在测试了20次,对此我没有其他解释,也许我做错了什么,或者我不知道

好的,我正在创建一个小部件,它使用领域数据库从中加载数据。我在应用程序级别声明了领域默认配置:

public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Realm.init(this);
        RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();
        Realm.setDefaultConfiguration(realmConfiguration);
    }
}
然后我将一些信息添加到MainActivity中的领域。我有运行RemoteViewsService的小部件提供程序来从领域加载数据并将其放入RemoteViewsFactory。这是RemoteViewsService,其中有趣的部分是:

public class MyWidService extends RemoteViewsService {
    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public MyWidFactory onGetViewFactory(Intent intent) {
        Log.d("MyWidService", " onGetViewFactory()<<<<<<<<<<");
        final Context context = getApplicationContext();
        Realm.init(context);
        Realm realm = Realm.getDefaultInstance();
        realm.isAutoRefresh();
        ArrayList<String> myList = new ArrayList<>();
        RealmResults<Task> myResults = realm.where(Task.class).findAll();
        final int myResLength = myResults.size();
        Log.d("myResLength", " "+ myResLength);
        for(int j = 0; j<myResLength; j++){
            myList.add(myResults.get(j).getTaskText());
            Log.d("tasks", " " + myList.get(j));
        }
        return new MyWidFactory(context, intent, myList);
    }

}
公共类MyWidService扩展了RemoteViewsService{
@凌驾
public void onCreate(){
super.onCreate();
}
@凌驾
公共MyWidFactory onGetViewFactory(意向){

Log.d(“MyWidService”、“onGetViewFactory()根据@EpicPandaForce的回答,我从服务中删除了Realm.init(),现在它工作得很好。谢谢!

您需要在
onGetViewFactory
中调用
Realm.init()
?因为这意味着一些非常棘手的事情正在发生,例如多进程。