因此,我正在开发一个俗气的应用程序,以便在我开始处理我公司的真实应用程序项目之前,在Android中训练自己.我遇到了一个让我度过非常艰难时期的错误.
我得到了一个我要使用的库依赖项列表,并设置了我的build.gradle文件来加载它们.它同步很好,所以我认为它是在我所知的最佳情况下完成的:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.android.gms:play-services:7.3.0'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.retrofit:retrofit:1.7.0'
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.squareup.dagger:dagger-compiler:1.2.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.squareup:otto:1.3.7'
compile 'com.path:android-priority-jobqueue:1.1.2'
compile 'io.realm:realm-android:0.80.1'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:22.1.1'
}
Run Code Online (Sandbox Code Playgroud)
我实际上已经安装了android支持库和存储库:
然而,我仍然尝试启动应用程序并获得以下堆栈跟踪:
java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$attr
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:286)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.anglersatalas.twitstagram.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at …
Run Code Online (Sandbox Code Playgroud) 因此,我正在为应用服务器的数据库添加上次更新时间。其想法是,它将记录对我们的行程之一应用更新的时间,然后该应用可以发送获取请求以弄清是否已获取所有正确的最新信息。
我已经将该列添加到我们的表中,并提供了全部服务,最后设法在每次对行程表中的行程进行更改时触发一个触发器来更新该列。我的问题现在来自以下事实:与旅行有关的信息也存储在许多其他表中(例如,存在构成旅行的路线的表以及用户可以在行程等),并且如果其中任何数据发生更改,则行程的更新时间也需要更改。我一辈子都想不通如何设置触发器,以便在更改某些路线信息时,该表所属路线的最后更新时间将被更新。
这是我现在的触发代码:当该行的行被更新时,它将更新该行表的最后更新的列。
CREATE OR REPLACE FUNCTION record_update_time() RETURNS TRIGGER AS
$$
BEGIN
NEW.last_updated=now();
RETURN NEW;
END;
$$
LANGUAGE PLPGSQL;
CREATE TRIGGER update_entry_on_entry_change
BEFORE UPDATE ON mydatabase.trip FOR EACH ROW
EXECUTE PROCEDURE record_update_time();
--I used the next two queries just to test that the trigger works. It
--probably doesn't make a difference to you but I'll keep it here for reference
UPDATE mydatabase.trip
SET title='Sample New Title'
WHERE id = 2;
SELECT *
FROM mydatabase.trip
WHERE mydatabase.trip.id < 5;
Run Code Online (Sandbox Code Playgroud)
现在,当用外键引用行的行更新时,我需要更新它。对SQL触发器比我更有经验的人有什么想法吗?