Java Android全局变量、getter、setter、error、,
我试着在“全局变量”中添加一些数据。“连接”类,无无效窗口Java Android全局变量、getter、setter、error、,,java,android,global-variables,Java,Android,Global Variables,我试着在“全局变量”中添加一些数据。“连接”类,无无效窗口 for (int in = 7; in < arAll.length; in++) { if (arAll[in].toString().endsWith("/")) { ((MyApplication) this.getApplication()).setPath(arAll[in] .toString()); } else {
for (int in = 7; in < arAll.length; in++) {
if (arAll[in].toString().endsWith("/")) {
((MyApplication) this.getApplication()).setPath(arAll[in]
.toString());
} else {
((MyApplication) this.getApplication()).setFile(arAll[in]
.toString());
}
for(int in=7;in
MyApplication getter's和setter's:
private ArrayList<String> file = new ArrayList<String>();
private ArrayList<String> path = new ArrayList<String>();
private ArrayList<String> all = new ArrayList<String>();
public void removeAll() {
this.file.clear();
this.path.clear();
this.all.clear();
}
public int len() {
return this.all.size();
}
public String getStrbyId (int i) {
return this.all.get(i).toString();
}
public ArrayList<String> getFile() {
return this.file;
}
public void setFile(String file) {
this.file.add(file);
setAll(file);
Log.v("",file);
}
public ArrayList<String> getPath() {
return this.path;
}
public void setPath(String path) {
this.path.add(path);
setAll(path);
Log.v("",path);
}
public ArrayList<String> getAll() {
Log.v("",String.valueOf(len()));
return this.all;
}
private void setAll(String all) {
this.all.add(all);
}
private ArrayList file=new ArrayList();
私有ArrayList路径=新建ArrayList();
private ArrayList all=new ArrayList();
公共无效删除所有(){
这个.file.clear();
this.path.clear();
这个。全部。清除();
}
公共int len(){
返回此.all.size();
}
公共字符串getStrbyId(int i){
返回此.all.get(i).toString();
}
公共ArrayList getFile(){
返回此文件;
}
公共void setFile(字符串文件){
this.file.add(文件);
setAll(文件);
Log.v(“,文件);
}
公共ArrayList getPath(){
返回此.path;
}
公共void setPath(字符串路径){
this.path.add(path);
setAll(路径);
Log.v(“,路径);
}
公共数组列表getAll(){
Log.v(“,String.valueOf(len());
把这个还给我;
}
私有void setAll(字符串全部){
此.all.add(全部);
}
在manifest
中,您通过应用程序上下文使用全局变量的事实很可能是您的应用程序中存在设计不正确的内容。您根本不需要使用这样的全局变量,这可能是导致错误的潜在原因(传递上下文并访问这些全局变量有时是必要的,但在这种情况下可能不是这样)。相反,您应该在组件之间传递必要的变量,并在每个组件中使用它们。(活动、服务、ContentProvider。)因此,也许你可以重新思考为什么需要全局变量,而不是试图让这个黑客程序正常工作。@user625565:你能在日志中公布错误吗?你看不到在哪里用onCreate()初始化“我的应用程序”…或发布整个代码和logcat入口查看此线程。您可以尝试使用getApplicationContext()
@user625565:使用adb logcat
、DDMS或Eclipse中的DDMS透视图查看logcat并检查与错误相关的堆栈跟踪。