【发布时间】:2018-04-05 14:00:01
【问题描述】:
所以我正在创建这个应用程序,并且我已经使用 RealmObject 创建了一个类。但是,每当我尝试创建另一个类时,我的应用程序就会停止工作。这只发生在我尝试创建一个扩展 RealmObject 的类时。它不会以任何其他方式发生。我已经有一个使用 RealmObject 的类。另外,我检查了logcat,它没有抛出任何错误消息。我该怎么办?
这是AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc.apps">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".profiles" />
<activity android:name=".view_profile" />
<activity android:name=".EditProfile" />
<activity android:name=".Quiz" />
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
</application>
</manifest>
这里是build.gradle (project: apps) :-
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "io.realm:realm-gradle-plugin:5.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这里是 build.gradle (Module:app)
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 26
configurations.all { resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9' }
defaultConfig {
applicationId "com.abc.apps"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.31.0'
compile 'com.android.support:multidex:1.0.3'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
这是导致错误的 RealmObject 类:-
import io.realm.RealmObject;
/**
* Created by Admin on 4/5/2018.
*/
public class showdata extends RealmObject {
String id;
}
【问题讨论】:
-
能否请您出示代码。因为没有代码很难说任何话。
-
@RishabhRawat 好的,我将在其中编辑它
-
@RishabhRawat 我添加了
-
请给出错误名称,因为您的代码完全正确。如果您的设备显示 ANR,请检查日志猫窗口。因为没有任何错误,应用程序如何停止工作。
-
见我之前的帖子。如果您愿意,请投票,因为您的问题可能会在我之前关于领域数据库的帖子中得到解决。 stackoverflow.com/questions/48880438/…
标签: android android-studio realm