创建表单时出现Titanium错误

时间:2014-10-13 10:11:29

标签: javascript titanium-mobile

我是钛appcelerator的新手,在创建带有文本字段和按钮的表单时出错。在此页面中有3个文本字段和一个按钮

这是我的代码

var win1 = Titanium.UI.currentWindow;
var aview = Titanium.UI.createView({
borderRadius : 10,
backgroundColor:'Red',
width : Titanium.UI.FILL,
height : Titanium.UI.FILL,
layout : 'vertical'
});
win1.add(aview);
    height : 'auto',
width : Titanium.UI.FILL,
top : 10,
left : 100,
right : 40,
bottom: 40,
text:'Registration',
color:'White'
 });
aview.add(headings);

var usern = Ti.UI.createLabel({
height : 'auto',
width : Titanium.UI.FILL,
top : 10,
left : 40,
right : 40,
text:'Username',

color:'black'
});
aview.add(usern);

var user = Ti.UI.createTextField({
borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
color: '#336699',
text:'Username',
height : 'auto',
width : Titanium.UI.FILL,
top : 10,
left : 40,
right : 40
});
aview.add(user);

var passn = Ti.UI.createLabel({
text:'Password',
height : 'auto',
width : Titanium.UI.FILL,
top : 10,
left : 40,
right : 40,    color:'black'
});
aview.add(passn);
var pass = Ti.UI.createTextField({
height : 'auto',
width : Titanium.UI.FILL,
top : 10,
left : 40,
right : 40,
text:'Password',
color: '#336699',
keyboardType: Titanium.UI.KEYBOARD_PHONE_PAD,// This has varities of keyboard and I choose  PHONE_PAD as layout and it displays number pad when we click on the edit box of the date
returnKeyType: Ti.UI.RETURNKEY_DONE,
passwordMask:true,//This makes the letter display in ***** format
  borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED

});
aview.add(pass);

var fname = Ti.UI.createLabel({
height : 'auto',
width : Titanium.UI.FILL,
top : 10,
left : 40,
right : 40,
text:'Fullname',
color:'black'
});
aview.add(fname);

var fn = Ti.UI.createTextField({
borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
color: '#336699',
text:'Fullname',
height : 'auto',
width : Titanium.UI.FILL,
top : 10,
left : 40,
right : 40

});
aview.add(fn);

var buttons = Ti.UI.createButton({
title: 'Submit',
height : 'auto',
width : 'auto',
top : 10,
left : '40%',
bottom : 10,
padding : '20%'
});
buttons.addEventListener('click',function(e)
{
  Ti.API.info("You clicked the button");
var win2 = Ti.UI.createWindow({  
url:'page2.js'
});
win2.open();
});

aview.add(buttons);

这些是我在运行应用程序时遇到的错误,请帮助

错误:

[ERROR] :  TiExceptionHandler: (main) [235,235] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,235] - In app.js:1,69
[ERROR] :  TiExceptionHandler: (main) [0,235] - Message: Uncaught TypeError: Cannot call method     'add' of null
[ERROR] :  TiExceptionHandler: (main) [0,235] - Source: h:Titanium.UI.FILL,height:Titanium.UI.FILL,layout:"vertical"});win1.add(aview)
[ERROR] :  V8Exception: Exception occurred at app.js:1: Uncaught TypeError: Cannot call method 'add' of null

1 个答案:

答案 0 :(得分:1)

检查一下:我认为这是你的app.js,如果是,它会起作用。

var win1 = Titanium.UI.createWindow({backgroundColor: "#ffffff"});
win1.open();
var aview = Titanium.UI.createView({
    borderRadius : 10,
    backgroundColor : 'Red',
    width : Titanium.UI.FILL,
    height : Titanium.UI.FILL,
    layout : 'vertical'
});
win1.add(aview);

var headings = Ti.UI.createLabel({
    height : 'auto',
    width : Titanium.UI.FILL,
    top : 10,
    left : 100,
    right : 40,
    bottom : 40,
    text : 'Registration',
    color : 'White'
});
aview.add(headings);

var usern = Ti.UI.createLabel({
    height : 'auto',
    width : Titanium.UI.FILL,
    top : 10,
    left : 40,
    right : 40,
    text : 'Username',

    color : 'black'
});
aview.add(usern);

var user = Ti.UI.createTextField({
    borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
    color : '#336699',
    text : 'Username',
    height : 'auto',
    width : Titanium.UI.FILL,
    top : 10,
    left : 40,
    right : 40
});
aview.add(user);

var passn = Ti.UI.createLabel({
    text : 'Password',
    height : 'auto',
    width : Titanium.UI.FILL,
    top : 10,
    left : 40,
    right : 40,
    color : 'black'
});
aview.add(passn);
var pass = Ti.UI.createTextField({
    height : 'auto',
    width : Titanium.UI.FILL,
    top : 10,
    left : 40,
    right : 40,
    text : 'Password',
    color : '#336699',
    keyboardType : Titanium.UI.KEYBOARD_PHONE_PAD, // This has varities of keyboard and I choose  PHONE_PAD as layout and it displays number pad when we click on the edit box of the date
    returnKeyType : Ti.UI.RETURNKEY_DONE,
    passwordMask : true, //This makes the letter display in ***** format
    borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED

});
aview.add(pass);

var fname = Ti.UI.createLabel({
    height : 'auto',
    width : Titanium.UI.FILL,
    top : 10,
    left : 40,
    right : 40,
    text : 'Fullname',
    color : 'black'
});
aview.add(fname);

var fn = Ti.UI.createTextField({
    borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
    color : '#336699',
    text : 'Fullname',
    height : 'auto',
    width : Titanium.UI.FILL,
    top : 10,
    left : 40,
    right : 40

});
aview.add(fn);

var buttons = Ti.UI.createButton({
    title : 'Submit',
    height : 'auto',
    width : 'auto',
    top : 10,
    left : '40%',
    bottom : 10,
    padding : '20%'
});
buttons.addEventListener('click', function(e) {
    Ti.API.info("You clicked the button");
    var win2 = Ti.UI.createWindow({
        url : 'page2.js'
    });
    win2.open();
});

aview.add(buttons);