Android:onCreate 之后的任何事情都没有发生
我得到了这个课程,但 onCreate 内没有任何反应?初始化时不会自动调用吗?
代码如下,非常感谢! - Micheal
package com.michealbach.livedrops;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.app.Activity;
public class AnyClass extends Activity {
double latitude = 0;
double longitude = 0;
String addressString = "Address Initialized";
String postalString = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
postalString = "Why doesn't this String change happen at all?";
}
public double getLongitude() {
return longitude;
}
public double getLatitude() {
return latitude;
}
public String getAddress() {
return addressString;
}
public String getPostal() {
return postalString;
}
}
这样做会导致“应用程序意外停止。请重试”。如果我将字符串初始化为某些字符集而不是 null,它就会保持这种状态。它不应该执行 onCreate() 内部的操作并进行更改吗?
I got this class, and nothing inside the onCreate is happening? Does it not automatically get called upon initialization?
Code is below, Thanks alot! - Micheal
package com.michealbach.livedrops;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.app.Activity;
public class AnyClass extends Activity {
double latitude = 0;
double longitude = 0;
String addressString = "Address Initialized";
String postalString = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
postalString = "Why doesn't this String change happen at all?";
}
public double getLongitude() {
return longitude;
}
public double getLatitude() {
return latitude;
}
public String getAddress() {
return addressString;
}
public String getPostal() {
return postalString;
}
}
Doing this results in a "application has stopped unexpectedly. Please try again". If I initialize the string to some set of characters instead of null, it'll just stay that way. Should it not do what is inside the onCreate() and make that change?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
onLocationChanged() 只是程序中的一个类方法,它没有连接到任何东西。你必须做
然后在你的 onCreate() 中
onLocationChanged() is just a class method in your program, it's not conected to anything. You have to do
And then in your onCreate()