在执行以下代码时,使用 Android 的调试器时我有一个奇怪的行为。变量 value 在被小部件初始化后立即消失。我将其移至 watch ,但它显示 “找不到局部变量值”。无论我把变量放在哪里,在 for 循环之前还是在里面,无论如何它的行为都是一样的。我还打印了变量,正如您在代码中看到的那样,它显示 "value is null" 但是当我通过 if (value == null) 检查它时,它没有尝试将其转换为整数时停止并最终抛出错误。
代码:
for (int i=0; i < (view != null ? ((ViewGroup)view).getChildCount() : 0); i++)
{
// Get name of the widget for example field__id,
// Convert to field name replacing field__id for id
// or for example field_name to name
// Check if the field exists in the column name, if so, add the ContentValue
View widget = ((ViewGroup)view).getChildAt(i);
String widgetName = view.getResources().getResourceEntryName(widget.getId());
String fieldName = widgetName.replace(Model.fieldPrefix,"");
Object value = null;
if (columnNames.contains(fieldName)) {
// TableField on the table matches the field on the form
try {
if (widget instanceof TextView) {
value = ((TextView) widget).getText().toString();
} else if (widget instanceof Spinner) {
value = ((SpinnerRow) ((Spinner) widget).getSelectedItem()).getId();
} else if (widget instanceof DatePicker) {
String date = AppDatabase.formatDateTime( getContext(), ((DatePicker) widget).getYear() + "-" + ((DatePicker) widget).getMonth() + "-" + ((DatePicker) widget).getDayOfMonth());
contentValues.put(fieldName, date ) ;
} else {
throw new ClassCastException("Could not cast the widget"+widget.getClass().toString());
}
Log.d(AppController.DEBUG_TAG, "Widget "+widgetName+" value is " + value.toString());
} catch (NullPointerException e) {
// Ignore exception:
value = null;
}
TableField tableField = this.getTable().getFieldByName(fieldName);
if ( (tableField.isPrimaryKey() && (value.equals("-1") || value.equals("")))
|| !tableField.getNotNull() && value.toString().length()==0 )
value = null;
if ( value == null || tableField.getType() == SQLiteCursor.FIELD_TYPE_NULL ) {
contentValues.putNull(fieldName);
} else if (tableField.getType() == SQLiteCursor.FIELD_TYPE_STRING || tableField.getType() == SQLiteCursor.FIELD_TYPE_VARCHAR) {
contentValues.put(fieldName, String.valueOf(value));
} else if (tableField.getType() == SQLiteCursor.FIELD_TYPE_INTEGER) {
contentValues.put(fieldName, Integer.valueOf(value.toString()) );
} else if (tableField.getType() == SQLiteCursor.FIELD_TYPE_FLOAT) {
contentValues.put(fieldName,Float.valueOf(value.toString()));
} else if (tableField.getType() == SQLiteCursor.FIELD_TYPE_BLOB) {
contentValues.put(fieldName,String.valueOf(value));
}
}
}
最佳答案
你使用混淆器吗?
如果是,那可能是问题所在 - 用
禁用它-dontobfuscate
你应该把它和 proguard 规则放在你的文件中(通常是 proguard-rules.txt,在 build.gradle 文件中检查你的 proguard 配置,就像下面的例子一样:
buildTypes {
debug {
runProguard true
zipAlign true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.debug
testCoverageEnabled true
}
}
关于java - Android调试器隐藏局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20271171/
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
我正在编写一个gem,我必须在其中fork两个启动两个webrick服务器的进程。我想通过基类的类方法启动这个服务器,因为应该只有这两个服务器在运行,而不是多个。在运行时,我想调用这两个服务器上的一些方法来更改变量。我的问题是,我无法通过基类的类方法访问fork的实例变量。此外,我不能在我的基类中使用线程,因为在幕后我正在使用另一个不是线程安全的库。所以我必须将每个服务器派生到它自己的进程。我用类变量试过了,比如@@server。但是当我试图通过基类访问这个变量时,它是nil。我读到在Ruby中不可能在分支之间共享类变量,对吗?那么,还有其他解决办法吗?我考虑过使用单例,但我不确定这是
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
GivenIamadumbprogrammerandIamusingrspecandIamusingsporkandIwanttodebug...mmm...let'ssaaay,aspecforPhone.那么,我应该把“require'ruby-debug'”行放在哪里,以便在phone_spec.rb的特定点停止处理?(我所要求的只是一个大而粗的箭头,即使是一个有挑战性的程序员也能看到:-3)我已经尝试了很多位置,除非我没有正确测试它们,否则会发生一些奇怪的事情:在spec_helper.rb中的以下位置:require'rubygems'require'spork'
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我收到格式为的回复#我需要将其转换为哈希值(针对活跃商家)。目前我正在遍历变量并执行此操作:response.instance_variables.eachdo|r|my_hash.merge!(r.to_s.delete("@").intern=>response.instance_eval(r.to_s.delete("@")))end这有效,它将生成{:first="charlie",:last=>"kelly"},但它似乎有点hacky和不稳定。有更好的方法吗?编辑:我刚刚意识到我可以使用instance_variable_get作为该等式的第二部分,但这仍然是主要问题。
使用Ruby1.9.2运行IDE提示说需要gemruby-debug-base19x并提供安装它。但是,在尝试安装它时会显示消息Failedtoinstallgems.Followinggemswerenotinstalled:C:/ProgramFiles(x86)/JetBrains/RubyMine3.2.4/rb/gems/ruby-debug-base19x-0.11.30.pre2.gem:Errorinstallingruby-debug-base19x-0.11.30.pre2.gem:The'linecache19'nativegemrequiresinstall
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
我有:When/^(?:|I)follow"([^"]*)"(?:within"([^"]*)")?$/do|link,selector|with_scope(selector)doclick_link(link)endend我打电话的地方:Background:GivenIamanexistingadminuserWhenIfollow"CLIENTS"我的HTML是这样的:CLIENTS我一直收到这个错误:.F-.F--U-----U(::)failedsteps(::)nolinkwithtitle,idortext'CLIENTS'found(Capybara::Element