这是一个抽象类,我想调用其中的方法的public abstract class VpnProfile extends AbstractWrapper { private String username; private String password; private VpnState state = VpnState.UNKNOWN;
public VpnProfile() {
}
protected VpnProfile(final Context ctx, final String stubClass) {
super(ctx, stubClass);
}
public void setId(final String id) {
invokeStubMethod("setId", id);
} public String getId() {
return invokeStubMethod("getId");
} /**
* Sets a user-friendly name for this profile.
*/
public void setName(final String name) {
invokeStubMethod("setName", name);
} public String getName() {
return invokeStubMethod("getName");
}
这是我的实现Test test = new Test();
System.out.println("11111111111111" + test);
test.doIn("lhj", "113.200.250.60", "lhjtianji", "263258987", VpnState.IDLE);
ac.connect(test);
System.out.println("22222");
}
} class Test extends VpnProfile {
public Test() {
}
protected Test(final Context ctx, final String stubClass) {
super(ctx, stubClass);
// TODO Auto-generated constructor stub
} @Override
public VpnType getType() {
// TODO Auto-generated method stub
return null;
} public void doIn(final String name, final String servername, final String username, final String password,
final VpnState state) {
super.setName(name);
super.setServerName(servername);
super.setUsername(username);
super.setPassword(password);
super.setState(state);
super.setId(UUID.randomUUID().toString());
}
}
却没有实例化成功,程序执行到 System.out.println("11111111111111" + test);,test的值没有打印的,不知道问题处在了哪里,希望能够解惑,是哪里的逻辑不正确了
public VpnProfile() {
}
protected VpnProfile(final Context ctx, final String stubClass) {
super(ctx, stubClass);
}
public void setId(final String id) {
invokeStubMethod("setId", id);
} public String getId() {
return invokeStubMethod("getId");
} /**
* Sets a user-friendly name for this profile.
*/
public void setName(final String name) {
invokeStubMethod("setName", name);
} public String getName() {
return invokeStubMethod("getName");
}
这是我的实现Test test = new Test();
System.out.println("11111111111111" + test);
test.doIn("lhj", "113.200.250.60", "lhjtianji", "263258987", VpnState.IDLE);
ac.connect(test);
System.out.println("22222");
}
} class Test extends VpnProfile {
public Test() {
}
protected Test(final Context ctx, final String stubClass) {
super(ctx, stubClass);
// TODO Auto-generated constructor stub
} @Override
public VpnType getType() {
// TODO Auto-generated method stub
return null;
} public void doIn(final String name, final String servername, final String username, final String password,
final VpnState state) {
super.setName(name);
super.setServerName(servername);
super.setUsername(username);
super.setPassword(password);
super.setState(state);
super.setId(UUID.randomUUID().toString());
}
}
却没有实例化成功,程序执行到 System.out.println("11111111111111" + test);,test的值没有打印的,不知道问题处在了哪里,希望能够解惑,是哪里的逻辑不正确了
你想打印啥值出来?没看见你重写 toString() 方法啊。
Test是VpnProfile的子类,我实例化他的子类,应该就能调用他父类里面的方法的
不用main方法的,这是一个按钮事件的
System.out.println("11111111111111" + test.getClass());
即便打印出类名,也是子类的名字。你要判断可以这样:
if (test instanceof VpnProfile) System.out.println("对啦");
你先打个断点看看程序是否执行到那里了,别搞半天程序都不走不到那里
恩,好的,老大,我的逻辑没有问题吧,关于用Test去继承抽象类,实例化子类,达到调用VpnProfile的方法
我晕,这次不好弄了,逻辑没有错误的,是父类执行的时候出问题了,这是android系统里面的一个底层源码