仅当我在Android上使用AIDE应用程序进行编码时才会遇到此问题(使用Android Studio时没有问题)。编译并安装我的应用程序后,当它启动时,MainActivity会停止。
设备名称:Nexus 6P(垂钓者)。
Android版:6.0.1
领域版本:1.1.0
AIDE版本:3.2.160525(最新版本)。
*日志:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.twitter.i_droidi.notah/com.twitter.i_droidi.notah.MainActivity}: java.lang.IllegalArgumentException: Notes is not part of the schema for this Realm
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2452)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5481)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Caused by: java.lang.IllegalArgumentException: Notes is not part of the schema for this Realm
at io.realm.internal.modules.CompositeMediator.getMediator(CompositeMediator.java:132)
at io.realm.internal.modules.CompositeMediator.getTableName(CompositeMediator.java:79)
at io.realm.RealmSchema.getSchemaForClass(RealmSchema.java:235)
at io.realm.RealmQuery.<init>(RealmQuery.java:136)
at io.realm.RealmQuery.createQuery(RealmQuery.java:85)
at io.realm.Realm.where(Realm.java:925)
at com.twitter.i_droidi.notah.RealmController.getNotes(RealmController.java:74)
at com.twitter.i_droidi.notah.MainActivity.onCreate(MainActivity.java:87)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405)
... 10 more
* MainActivity.java:
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private Toolbar toolbar = null;
private NavigationView navigationView = null;
private NotesAdapter adapter;
private Realm realm;
private RecyclerView recyclerView;
private RealmChangeListener realmChangeListener;
private TextView textView1;
private TextView textView2;
private String version;
private TextView versionText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.realm = RealmController.with(this).getRealm();
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
textView1 = (TextView) findViewById(R.id.textView1);
textView2 = (TextView) findViewById(R.id.textView2);
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.coordinatorlayout_drawerlayout_mainactivity);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navi_drawer_open, R.string.navi_drawer_close);
drawerLayout.setDrawerListener(toggle);
toggle.syncState();
try
{
PackageInfo packageInfo = getApplicationContext().getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), PackageManager.GET_ACTIVITIES);
version = packageInfo.versionName;
}
catch(PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}
versionText = (TextView) findViewById(R.id.app_version);
if(versionText != null)
versionText.setText(version);
navigationView = (NavigationView) findViewById(R.id.nav_view);
setupRecycler();
setRealmAdapter(RealmController.with(this).getNotes());
...
* RealmController.java:
public class RealmController {
private static RealmController instance;
private final Realm realm;
private RealmController(Application application)
{
realm = Realm.getDefaultInstance();
}
private static RealmController with(Fragment fragment)
{
if(instance == null)
{
instance = new RealmController(fragment.getActivity().getApplication());
}
return instance;
}
protected static RealmController with(Activity activity)
{
if(instance == null)
{
instance = new RealmController(activity.getApplication());
}
return instance;
}
private static RealmController with(Application application)
{
if(instance == null)
{
instance = new RealmController(application);
}
return instance;
}
protected static RealmController getInstance()
{
return instance;
}
protected Realm getRealm()
{
return realm;
}
protected void refresh()
{
realm.waitForChange();
}
private void clearAll()
{
realm.beginTransaction();
RealmResults<Notes> results = realm.where(Notes.class).findAll();
results.deleteAllFromRealm();
realm.commitTransaction();
}
protected RealmResults<Notes> getNotes()
{
return realm.where(Notes.class).findAll();
}
private Notes getNote(int id)
{
return realm.where(Notes.class).equalTo("id", id).findFirst();
}
protected boolean hasNotes()
{
return !realm.where(Notes.class).findAll().isEmpty();
}
}
* Notes.java:
public class Notes extends RealmObject {
@PrimaryKey
private int id;
private String title;
private String body;
private String date;
protected int getId() {
return id;
}
protected void setId(int id) {
this.id = id;
}
protected String getTitle() {
return title;
}
protected void setTitle(String title) {
this.title = title;
}
protected String getBody() {
return body;
}
protected void setBody(String body) {
this.body = body;
}
protected String getDate() {
return date;
}
protected void setDate(String date) {
this.date = date;
}
}