Skip to content

Trying to display keyboard on Windows UWP device crashes app #1965

Description

@mwarnett

Displaying a simple form in preparation for a search. User taps in TextField to give it focus and display the keyboard. The app crashes.

Sample code to reproduce the problem, run app and then tap in the TextField

Using a Microsoft Lumia 640 LTE phone for testing.

`package com.mycompany.myapp;

import com.codename1.components.InfiniteProgress;
import com.codename1.components.ToastBar;
import com.codename1.components.WebBrowser;
import com.codename1.ui.AutoCompleteTextField;
import com.codename1.ui.Button;
import com.codename1.ui.ComboBox;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.FontImage;
import com.codename1.ui.Label;
import com.codename1.ui.spinner.Picker;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import com.codename1.ui.Command;
import com.codename1.ui.Component;
import com.codename1.ui.Container;
import com.codename1.ui.TextField;
import com.codename1.ui.Toolbar;
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.FlowLayout;
import com.codename1.ui.layouts.GridBagConstraints;
import com.codename1.ui.layouts.GridBagLayout;
import com.codename1.ui.layouts.Insets;
import com.codename1.ui.plaf.Style;
import java.io.IOException;
import java.util.Vector;

/**

  • This file was generated by Codename One for the purpose

  • of building native mobile applications using Java.
    */
    public class MyApplication implements ActionListener {

    private Form current;
    private Resources theme;
    private Command _backCommand;
    private ComboBox _searchBy;
    private TextField _searchFor;
    private Button _searchForRedo;
    private ComboBox _sortBy;
    private InfiniteProgress _progress;
    private Label _statusMessage;
    private Command _searchCommand;
    private Command _scanCommand;

    public void init(Object context) {
    theme = UIManager.initFirstTheme("/theme");

     // Enable Toolbar on all Forms by default
     Toolbar.setGlobalToolbar(true);
    
     // Pro only feature, uncomment if you have a pro subscription
     // Log.bindCrashProtection(true);
    

    }

    public void start() {
    if(current != null){
    current.show();
    return;
    }

     Form searchForm = new Form("Sample App");
    
     // Allow scrolling if screen too small or rotated
     searchForm.setScrollableY(true);
     searchForm.setScrollVisible(true);
    
     searchForm.addCommandListener(this);
    
     _backCommand = new Command("Back");
     searchForm.setBackCommand(_backCommand);
    
     GridBagLayout gbl = new GridBagLayout();
     GridBagConstraints gbc = new GridBagConstraints();
     searchForm.setLayout(gbl);
    
     int y = 0;
     int x = 0;
     Label searchBy = new Label("Search by");
    
     gbc.anchor        = GridBagConstraints.NORTHWEST;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = 1;
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.BOTH;
     gbc.weightx       = 0.0;
     gbc.weighty       = 0.0;
     gbc.insets        = new Insets(0, 5, 5, 0);
     gbl.setConstraints(searchBy, gbc);
     searchForm.addComponent(searchBy);
     x++;
    
     String[] searchByList = { "Author", "Title"};
     _searchBy = new ComboBox((Object[]) searchByList);
     _searchBy.setSelectedIndex(0);
     _searchBy.addActionListener(this);
     gbc.anchor        = GridBagConstraints.NORTHWEST;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = GridBagConstraints.REMAINDER;
    
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.HORIZONTAL;
     gbc.weightx       = 0.1;
     gbc.weighty       = 0.0;
     gbc.insets        = new Insets(0, 5, 5, 5);
     gbl.setConstraints(_searchBy, gbc);
     searchForm.addComponent(_searchBy);
    
     y++;
     x = 0;
     Label searchFor = new Label("Search For:");
    
     gbc.anchor        = GridBagConstraints.SOUTHWEST;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = 1;
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.BOTH;
     gbc.weightx       = 0.0;
     gbc.weighty       = 0.0;
     gbc.insets        = new Insets(0, 5, 10, 0);
     gbl.setConstraints(searchFor, gbc);
     searchForm.addComponent(searchFor);
    
     x++;
     _searchFor = new TextField();
     _searchFor.setColumns(8);
     _searchFor.setInputMode("abc");
     _searchFor.setConstraint(TextField.ANY | TextField.NON_PREDICTIVE);
     _searchFor.setDoneListener(this);
     _searchFor.putClientProperty("searchField", true);
    
     gbc.anchor        = GridBagConstraints.SOUTHWEST;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = 1;
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.HORIZONTAL;
     gbc.weightx       = 0.1;
     gbc.weighty       = 0.0;
     gbc.insets        = new Insets(0, 5, 10, 5);
     gbl.setConstraints(_searchFor, gbc);
     searchForm.addComponent(_searchFor);
    
     y++;
     x = 0;
     Label sortBy = new Label("Sort By:");
    
     gbc.anchor        = GridBagConstraints.NORTHWEST;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = 1;
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.BOTH;
     gbc.weightx       = 0.0;
     gbc.weighty       = 0.0;
     gbc.insets        = new Insets(0, 5, 0, 0);
     gbl.setConstraints(sortBy, gbc);
     searchForm.addComponent(sortBy);
    
     x++;
     String[] sortByList = { "Author", "Title"};
     _sortBy = new ComboBox((Object[]) sortByList);
     _sortBy.setSelectedIndex(0);
    
     gbc.anchor        = GridBagConstraints.NORTHWEST;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = GridBagConstraints.REMAINDER;
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.HORIZONTAL;
     gbc.weightx       = 0.1;
     gbc.weighty       = 0.0;
     gbc.insets        = new Insets(0, 5, 0, 5);
     gbl.setConstraints(_sortBy, gbc);
     searchForm.addComponent(_sortBy);
    
     y++;
     x = 0;
     _progress = new InfiniteProgress();
     _progress.setVisible(false);
    
     /*
      * Put in container, we want this component to be invisible initially.
      * If we add it directly when it is hidden, no space is allocated
      * and it is never shown.
      */
     Container progress = new Container(new FlowLayout());
     progress.addComponent(_progress);
     gbc.anchor        = GridBagConstraints.NORTH;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = GridBagConstraints.REMAINDER;
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.NONE;
     gbc.weightx       = 0.0;
     gbc.weighty       = 0.0;
     gbc.insets        = new Insets(0, 10, 0, 10);
     gbl.setConstraints(progress, gbc);
     searchForm.addComponent(progress);
    
     y++;
     x = 0;
     _statusMessage = new Label(" ");
     _statusMessage.setPreferredW(500);
     Style style = _statusMessage.getStyle();
     style.setAlignment(Component.CENTER);
     gbc.anchor        = GridBagConstraints.NORTHWEST;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = GridBagConstraints.REMAINDER;
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.HORIZONTAL;
     gbc.weightx       = 0.0;
     gbc.weighty       = 0.0;
     gbc.insets        = new Insets(0, 10, 0, 10);
     gbl.setConstraints(_statusMessage, gbc);
     searchForm.addComponent(_statusMessage);
    
    
     y++;
     x = 0;
     Container buttons = new Container();
     buttons.setLayout(new FlowLayout(Component.CENTER));
     _scanCommand = new Command("Scan");
     Button scanButton = new Button(_scanCommand);
     buttons.addComponent(scanButton);
     _searchCommand = new Command("Search");
     Button searchButton = new Button(_searchCommand);
     buttons.addComponent(searchButton);
    
     gbc.anchor        = GridBagConstraints.NORTHWEST;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = GridBagConstraints.REMAINDER;
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.HORIZONTAL;
     gbc.weightx       = 0.0;
     gbc.weighty       = 0.0;
     gbc.insets        = new Insets(0, 10, 10, 10);
     gbl.setConstraints(buttons, gbc);
     searchForm.addComponent(buttons);
    
    
     y++;
     x = 0;
     Label filler = new Label();
    
     gbc.anchor        = GridBagConstraints.NORTHWEST;
     gbc.gridx         = x;
     gbc.gridy         = y;
     gbc.gridwidth     = 1;
     gbc.gridheight    = 1;
     gbc.fill          = GridBagConstraints.VERTICAL;
     gbc.weightx       = 0.0;
     gbc.weighty       = 0.1;
     gbc.insets        = new Insets(0, 0, 0, 0);
     gbl.setConstraints(filler, gbc);
     searchForm.addComponent(filler);
    
     searchForm.show();
    

    }

    public void stop() {
    current = Display.getInstance().getCurrent();
    if(current instanceof Dialog) {
    ((Dialog)current).dispose();
    current = Display.getInstance().getCurrent();
    }
    }

    public void destroy() {
    }

    public void actionPerformed(ActionEvent actionEvent) {
    Command command = actionEvent.getCommand();

     if (command == _backCommand) {
         stop();
         Display.getInstance().exitApplication();
         return;
     }
    

    }
    }
    `

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions