当我按下主页按钮时,应该暂停应用程序,保存所有状态并正常工作.相反,我得到这个错误:
java.lang.RuntimeException:无法暂停活动{be.test.tester/be.test.tester.DataScreen}:java.lang.IllegalStateException:派生类未在android.app.ActivityThread.performPauseActivity中调用super.onSaveInstanceState() (ActivityThread.java:3641)位于android.app.A活动时的android.app.ActivityThread.performPauseActivity(ActivityThread.java:3598),android.app.A活动.事件(ActivityThread.java:3574),android.app.ActivityThread.access $ 2500(ActivityThread.java) :136)在android.app.A.运行时,Android.O.Roper.loop(Looper.java:143)的android.app.Handler.dispatchMessage(Handler.java:99)上的android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2186)在android.app.ActivityThread.main(ActivityThread.java:5068)的java.lang.reflect.Method.invokeNative(Native Method),位于com.android的java.lang.reflect.Method.invoke(Method.java:521) .internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:858)位于dalvik.system.NativeStart.mai的com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)n(原生方法)
引起:java.lang.IllegalStateException:派生类没有在android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1207)的android.view.View.dispatchSaveInstanceState(View.java:6087)中调用super.onSaveInstanceState() android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:1207)at android.view.View.saveHierarchyState(View.java:6068)at com.android.internal.policy.impl.PhoneWindow.saveHierarchyState(PhoneWindow.java:1475)在android.app.A活动状态(Activity.java:1056)的android.app.A活动中的android.app.A活动状态(Activity.java:1056)的android.app.A活动状态中的android.app.Activity.onSaveInstanceState(Activity.java:1106). ActivityThread.performPauseActivity(ActivityThread.java:3623)...还有12个
我的活动在触摸时做出反应:
public class DataScreen extends Activity implements OnGestureListener{
Run Code Online (Sandbox Code Playgroud)
我从意图中获得了一些额外的东西:
totUsage = Integer.parseInt(getIntent().getStringExtra("extraTotUsage"));
limit = Integer.parseInt(getIntent().getStringExtra("extraLimit"));
Bundle bundle = getIntent().getExtras();
mylist = (ArrayList<HashMap<String, String>>) bundle.get("extraMyList");
Run Code Online (Sandbox Code Playgroud)
自定义视图显示数据(画布).在屏幕上滚动时,数据会在自定义视图(set,get方法)中更改并重绘自身.
我真的没有在这里管理onSaveInstanceState,不知道我是否必须这样做.
我的应用程序是堆栈的顶部,因为:
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Run Code Online (Sandbox Code Playgroud)
我不明白这个错误.
我有一对看起来像这样的课程;
public abstract class Class1 {
//...
public Class1() {
//...
function2();
//...
}
protected abstract void function2();
}
public class Class2 implements Class1 {
private final OnSomethingListener mOnSomethingListener = new OnSomethingListener() {
@Override
onSomething() {
doThatOtherThing();
}
}
protected void function2() {
//uses mOnSomethingListener
//however mOnSomethingListener is null when this function is called from super()
//...
}
public Class2() {
super();
}
}
Run Code Online (Sandbox Code Playgroud)
我假设监听器是null因为我有效地引用它super()并且它还没有实例化.但是,我想成功,final因为它确实如此.我可以让这个字段(监听器)及时初始化而不将它放在超类中(它不会使用监听器)吗?
我对这段代码感到有点困惑:
class A{
class B{
}
}
class C extends A.B{
C(A a){
a.super();
}
}
Run Code Online (Sandbox Code Playgroud)
它是什么意思:"a.super();" ?之前我认为超级链接到她的父类,但"超级()" - 链接到父的构造函数,但实际上类A没有父类(不介意对象......),那么它是什么意思超级在这种背景下?
大家好.
我读过这解释之间的差异的其他问题__init__和__new__,但我就是不明白,为什么在与Python 2了下面的代码:
init
Run Code Online (Sandbox Code Playgroud)
和Python3:
new
init
Run Code Online (Sandbox Code Playgroud)
示例代码:
class ExampleClass():
def __new__(cls):
print ("new")
return super().__new__(cls)
def __init__(self):
print ("init")
example = ExampleClass()
Run Code Online (Sandbox Code Playgroud) package Geometry;
public abstract class GeometryFigures{
protected double surfaces;
protected double perimeter;
public GeometryFigures(double surfaces, double perimeter) {
super(); //**<---Why use super call here?**
this.surfaces= surfaces;
this.perimeter= perimeter;
}
public double getSurfaces() {
return surfaces;
}
public double getPerimetre() {
return perimeter;
}
}
Run Code Online (Sandbox Code Playgroud)
所以基本上一切都在标题中.我想知道为什么我需要在超类中使用super().
谢谢你的帮助.
我正在尝试编写定义super类型习惯用法的模板类的变体.该类Inherit引入了类型Super来表示可能非常长的超类型,并且还需要知道派生类型New来做一些我没有在这里展示的额外的东西.
如果传递给的类型New不是模板,但是模板失败,则此方法正常.这是一个用clang++-3.8 -std=c++1y -Wall(gcc给出相同的输出)编译的完整示例:
struct SomeBase {};
template<class New, class Base>
struct Inherit : Base {
using Super = Inherit<New, Base>;
};
struct NonTemplate : Inherit<NonTemplate, SomeBase> {
using X = Super;
// compiles and is nice and short
};
template<class T>
struct Template : Inherit<Template<T>, SomeBase>
{
using A = Super;
// error: unknown type name 'Super'; did you mean 'NonTemplate::Super'?
using B …Run Code Online (Sandbox Code Playgroud) 我问这个问题,因为关于这个主题的每一个其他页面似乎都转变为过于简单的案例或对范围之外的细节进行随机讨论.
class Base:
def __init__(self, arg1, arg2, arg3, arg4):
self.arg1 = arg1
self.arg2 = arg2
self.arg3 = arg3
self.arg4 = arg4
class Child(Base):
def __init__(self, arg1, arg2, arg3, arg4, arg5):
super(Child).__init__(arg1, arg2, arg3, arg4)
self.arg5 = arg5
Run Code Online (Sandbox Code Playgroud)
这就是我尝试过的.我被告知我需要使用类型而不是classobj,但我不知道这意味着什么,谷歌没有帮助.
我只是想让它发挥作用.在Python 2.7中这样做的正确做法是什么?
class MyObject1(object):
def __init__(self):
super(MyObject1, self).__init__()
pass
class MyObject2(object):
def __init__(self, arg):
super(MyObject2, self).__init__()
pass
Run Code Online (Sandbox Code Playgroud)
我读过这样的python27代码,
我知道“超级”是指父类构造函数,
但我不明白为什么这两个类称自己为'构造函数' __init__',
好像没什么实际效果。
我正在查看钻石问题并得到一个问题:
class A:
def __init__(self):
print("This is class A")
class B(A):
def __init__(self):
print("This is class B")
super().__init__()
class C(A):
def __init__(self):
print("This is class C")
super().__init__()
class D(B, C):
def __init__(self):
print("This is class D")
super().__init__()
i = D()
Run Code Online (Sandbox Code Playgroud)
This is class D
This is class B
This is class C
This is class A
Run Code Online (Sandbox Code Playgroud)
它按预期工作,这很好,但我想知道为什么super().__init__()inclass B不去class A而是 C 被调用。
如果一个类有一个 super() 并且它继承自一个父类,它应该去那里。
如果我在 B 上删除它,代码将不会到达 C 或 A。
我知道 MRO 以及它是如何按预期进行的:
>>> …Run Code Online (Sandbox Code Playgroud) 这是我的父类,它具有trigger方法,即public方法:
class BaseEffect {
//properties and contructor...
//other methods...
public trigger = (): void => void (this.target.hitPoint -= this.amount);
}
Run Code Online (Sandbox Code Playgroud)
和一个TurnBasedEffect扩展BaseEffect类:
class TurnBasedEffect extends BaseEffect {
//properties and contructor...
//other methods...
public trigger = (): void => {
super.trigger();
this.remainingTurns--;
};
}
Run Code Online (Sandbox Code Playgroud)
这个类也有trigger方法,在这个方法里面,trigger调用了父类的一个方法。
问题是当trigger调用派生类的方法时,打字稿会抛出此错误:
TypeError: (intermediate value).trigger is not a function
Run Code Online (Sandbox Code Playgroud)
并指向该类trigger方法的这一行TurnBasedEffect:
//...
super.trigger();
//...
Run Code Online (Sandbox Code Playgroud)
我的课程有什么问题以及如何解决这个问题?
super ×10
python ×4
class ×3
java ×3
inheritance ×2
android ×1
arguments ×1
c++ ×1
construction ×1
crtp ×1
init ×1
javascript ×1
null ×1
python-2.7 ×1
python-2.x ×1
python-3.x ×1
templates ×1
typename ×1
typescript ×1