小编Zhe*_*Xin的帖子

使用findViewById()找不到视图

即使ID确实存在,我也无法TextView通过呼叫找到findViewById().

OtherActivity:

public class OtherActivity extends Activity { 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        TextView textView = (TextView)findViewById(R.ID.txt02);
        super.onCreate(savedInstanceState);//line 5
        setContentView(R.layout.other_activity);
        //textView.setText(ACCESSIBILITY_SERVICE);
        Button button = (Button)findViewById(R.ID.otherActivity_Btn);
        button.setText(R.string.otherActivityBtn);
        button.setOnClickListener(new GoBackBtnListener(this));
    }

    class GoBackBtnListener implements OnClickListener {
        OtherActivity other = null;
        public GoBackBtnListener(OtherActivity p_other) {
            other = p_other;
        }
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(other, Activity01Activity.class);
            other.startActivity(intent);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在第5行添加了断点,并以调试模式启动了项目.当它在断点处停止时,我将鼠标移动到变量textView,它为空.

other_activity布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-view findviewbyid

5
推荐指数
1
解决办法
3万
查看次数

在xml(Oracle)中使用命名空间时如何通过xmltable解析xml

我想解析一个xml字符串,它是从servier发送的Web服务响应,xml如下所示:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <addResponse xmlns="http://tempuri.org/">
            <addResult>20</addResult>
        </addResponse>
    </soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)

我想在元素addResult之间获得值20.我的plsql代码段如下所示:

declare
  v_xml clob;
begin
  v_xml := '<?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
      <addResponse xmlns="http://tempuri.org/">
        <addResult>20</addResult>
      </addResponse>
    </soap:Body>
  </soap:Envelope>';
  for c in (select results 
        from xmltable('Envelope/Body/addResponse' passing xmltype(v_xml) 
        columns results varchar(100) path './addResult')
       )
  loop
    dbms_output.put_line('the result of calculation is : ' || c.results);
  end loop;
end;
Run Code Online (Sandbox Code Playgroud)

似乎没有打印出任何东西,但是如果我删除命名空间'soap',代码运行良好,那么任何人都能告诉我当xml具有命名空间时如何获得值20?

xml oracle plsql

4
推荐指数
1
解决办法
1万
查看次数