草庐IT

android - 无法添加窗口错误

coder 2023-12-29 原文

我正在使用 tabWidget。当我第一次从父类转到子类并选择日期时,我的子类中有一个日期选择器,它工作正常,当我再次从父类转到子类并选择日期时,应用程序崩溃并显示 logcat 结果“无法添加窗”

第一次用还好,下次就不行了 代码如下

import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
public class PlaceOrder extends Activity {
    public TextView tvDisplayDate,personName,Cname,cAdrress;
    public DatePicker dpResult;
    public Button btnChangeDate;
    Button cancel,submit;
    public int year;
    public int month;
    public int day;
    int requestCode;
    int resultCode;
    Intent data;
    String Name,cName,Title,Address,Phone,Email;
    static final int DATE_DIALOG_ID = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.placeorder);
        personName=(TextView)findViewById(R.id.firstName);
        Cname=(TextView)findViewById(R.id.Cname);
        cAdrress=(TextView)findViewById(R.id.CAddname);
        personName.setText(AccountInfo.fnameNlName);
        Cname.setText(AccountInfo.cName);
        cAdrress.setText(AccountInfo.cAdd);
        setCurrentDateOnView();
        addListenerOnButton();
        final PlaceOrder PO = this;
        cancel=(Button)findViewById(R.id.Cancel);
        cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(FastPkgMainActivity.fastPackge==1)
                {
                    Intent fastPkgQuote = new Intent(v.getContext(), FastPkgQuote.class);
                    StringBuffer urlString = new StringBuffer();
                    FastPkgQuote parentActivity = (FastPkgQuote)getParent();
                    parentActivity.replaceContentView("fastpkg1", fastPkgQuote);
                }
                else if(FastPkgMainActivity.fastPackge==2)
                {
                    Intent fastpkgQuoteNew = new Intent(v.getContext(), FastPkgQuoteNew.class);
                    StringBuffer urlString = new StringBuffer();
                    FastPkgQuoteNew parentActivity = (FastPkgQuoteNew)getParent();
                    parentActivity.replaceContentView1("fastPkg2", fastpkgQuoteNew);
                }
                // TO*DO Auto-generated method stub
            }
        }
        );
        submit=(Button)findViewById(R.id.Submit);
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    Name=AccountInfo.fnameNlName.toString();
                    cName=AccountInfo.cName.toString();
                    Title=AccountInfo.title.toString();
                    Address=AccountInfo.cAdd.toString();
                    Phone=AccountInfo.phno.toString();
                    Email=AccountInfo.E_ID.toString();
                }
                catch (NullPointerException e) {
                    Name=" ";
                    cName=" ";
                    Title=" ";
                    Address=" ";
                    Phone=" ";
                    Email=" ";
                }
                // TODO Auto-generated method stub
                Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                //String[] recipients = new String[]{
                    "mymail@email.com", "sales@fastpkg.com",
                }
                ;
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                new String[] {
                    "sales@fastpkg.com"
                }
                );
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Placing an Order");
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "CustomerDetails       " +
                " Name"+":  "+Name+
                "CompanyName:"+"  "+cName+
                "Title :"+Title+
                "Address: "+Address+
                "Phone #: "+Phone+
                "Email :"+Email
                );
                emailIntent.setType("text/plain");
                startActivityForResult(Intent.createChooser(emailIntent, "Send mail client :"),RESULT_OK);
                onActivityResult(requestCode, resultCode, data);
            }
        }
        );
    }
    protected void onActivityResult(int requestCode, int resultCode,
    Intent data) {
        if (requestCode == 0) {
            if (resultCode == RESULT_CANCELED) {
                if(FastPkgMainActivity.fastPackge==1)
                {
                    Intent fastpkgQuote = new Intent();
                    StringBuffer urlString = new StringBuffer();
                    fastpkgQuote.setClass(getParent(), FastPkgQuote.class);
                    FastPkgQuote parentActivity = (FastPkgQuote)getParent();
                    parentActivity.replaceContentView("fastPkg2", fastpkgQuote);
                }
                else if(FastPkgMainActivity.fastPackge==2)
                {
                    Intent fastpkgQuoteNew = new Intent();
                    StringBuffer urlString = new StringBuffer();
                    fastpkgQuoteNew.setClass(getParent(),
                    FastPkgQuoteNew.class);
                    FastPkgQuoteNew parentActivity =
                    (FastPkgQuoteNew)getParent();
                    parentActivity.replaceContentView1("fastPkg2",
                    fastpkgQuoteNew);
                }
            }
            else if(resultCode==RESULT_OK)
            {
                final PlaceOrder pOrder = this;
                Intent intent = new Intent();
                intent.setClass(pOrder, ThnkYouPage.class);
                startActivity(intent);
            }
        }
    }
    // display current date
    public void setCurrentDateOnView() {
        tvDisplayDate = (TextView) findViewById(R.id.tvDate);
        dpResult = (DatePicker) findViewById(R.id.dpResult);
        dpResult.setVisibility(View.INVISIBLE);
        final Calendar c = Calendar.getInstance();
        year = c.get(Calendar.YEAR);
        month = c.get(Calendar.MONTH);
        day = c.get(Calendar.DAY_OF_MONTH);
        // set current date into textview
        tvDisplayDate.setText(new StringBuilder()
        // Month is 0 based, just add 1
        .append(month + 1).append("-").append(day).append("-")
        .append(year).append(" "));
        // set current date into datepicker
        dpResult.init(year, month, day, null);
    }
    public void addListenerOnButton() {
        btnChangeDate = (Button) findViewById(R.id.btnChangeDate);
        btnChangeDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        }
        );
    }
    @Override
    public  Dialog onCreateDialog(int id) {
        switch (id) {
            case DATE_DIALOG_ID:
            // set date picker as current date
            return new DatePickerDialog(this.getParent(), datePickerListener, year, month,
            day);
        }
        return null;
    }
    public  DatePickerDialog.OnDateSetListener datePickerListener = new
    DatePickerDialog.OnDateSetListener() {
        // when dialog box is closed, below method will be called.
        public void onDateSet(DatePicker view, int selectedYear,
        int selectedMonth, int selectedDay) {
            year = selectedYear;
            month = selectedMonth;
            day = selectedDay;
            // set selected date into textview
            tvDisplayDate.setText(new StringBuilder().append(month + 1)
            .append("-").append(day).append("-").append(year)
            .append(" "));
            // set selected date into datepicker also
            dpResult.init(year, month, day, null);
        }
    }
    ;
}

最佳答案

OnCreateDialog 方法中,在行中:

return new DatePickerDialog(this.getParent(), datePickerListener, year, month,day);

使用application basecontext代替this.getparent()

它可能对你有帮助。

关于android - 无法添加窗口错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10293188/

有关android - 无法添加窗口错误的更多相关文章

  1. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  4. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  5. ruby - 将 Bootstrap Less 添加到 Sinatra - 2

    我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它

  6. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  7. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  8. ruby - 续集在添加关联时访问many_to_many连接表 - 2

    我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以

  9. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  10. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

随机推荐