【问题标题】:Force close when clicking a Spinner inside a new Activity.在新 Activity 中单击 Spinner 时强制关闭。
【发布时间】:2013-03-12 03:02:44
【问题描述】:

我创建了一个TabHost,其中包含三个选项卡。如果我点击我的一个标签, 将打开带有 SpinnerActivity。如果我点击 Spinner,我的应用程序将关闭。

我的活动:

setContentView(R.layout.employeepayslip);
    btn=(Button)findViewById(R.id.button1);  //Submit

    Bundle extras = getIntent().getExtras();
    idviewslip = extras.getString("idviewslip");

     empid=(TextView)findViewById(R.id.empid1);
     empname=(TextView)findViewById(R.id.empname1);
     empdesignation=(TextView)findViewById(R.id.empdesignation);

    sp1=(Spinner) findViewById(R.id.spinner1);
    ArrayAdapter<String>Adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,months);
    sp1.setAdapter(Adapter);
    sp1.setOnItemSelectedListener(this);

    sp2=(Spinner) findViewById(R.id.spinner2);
    ArrayAdapter<String>Adapter1=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,years);
    sp2.setAdapter(Adapter1);
    sp2.setOnItemSelectedListener(this);

【问题讨论】:

  • 检查您的 logcat 并查看它在哪里崩溃。如果不清楚,请在此处发布您的 logcat 和相关代码。
  • 发布你的整个 logcat。异常可能从其他地方一直向上传播。
  • 请提供更具体的日志。但我猜你的活动还没有完全创建。
  • 感谢所有三个给我即时响应的人。现在,我得到了解决方案并发布为答案

标签: java android android-activity android-tabhost forceclose


【解决方案1】:

我只是替换了以下

setContentView(R.layout.employeepayslip);

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.employeepayslip, null);
    this.setContentView(viewToLoad);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    相关资源
    最近更新 更多