非静态方法' inflate(byte [],int,int)'无法从静态上下文引用

时间:2017-05-17 12:58:16

标签: java android

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view= Inflater.inflate(R.layout.reg_book,container,false);
    return view;
    }

背景信息:我是Android的初学者,我面临的错误是"非静态方法不能从静态上下文引用"。错误显示在' .inflate'。

2 个答案:

答案 0 :(得分:2)

更改此行

import React from 'react';



export default class Stories extends React.Component {
    constructor(props) {
        super(props);
        this.handleClose = this.handleClose.bind(this);
        this.handlePost = this.handlePost.bind(this);

    }
    handleClose() {
        this.props.handleClose();
    }
    handlePost(){
        let header = document.querySelector("#title-input").value;
        let description = document.querySelector("#description-story-input").value;
        let broker = document.querySelector("#broker-input").value;
        this.props.handlePost(header,description,broker);
    }


    render() {
        return (<div className={'popup-cls add-story-top'}>
            <div className={'add-story email-class'}>
                <img onClick={this.handleClose} className="cross-cls" src="src/img/cross.png" alt="Smiley face" height="35" width="35" />
                <h4 className="list-header">Create Stories</h4>
                <table>
                    <tbody>
                        <tr>
                            <td>
                                Title
                                </td>
                            <td>
                                <input type="text" id="title-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Description </td>
                            <td> <textarea rows="4" cols="50" id="description-story-input"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Broker </td>
                            <td> <input type="text" id="broker-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Ticker </td>
                            <td> <input type="text" id="ticker-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Category </td>
                            <td> <input type="text" id="category-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Direction </td>
                            <td> <input type="number" min="-2" max="2" defaultValue="0" id="direction-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Rating </td>
                            <td> <input type="number" min="-5" max="5" defaultValue="0" id="rating-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Score </td>
                            <td> <input type="number" min="-4" max="4" defaultValue="0" id="score-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Trade Price </td>
                            <td> <input type="text" id="trade-price-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Pre Trade Price </td>
                            <td> <input type="text" id="pre-trade-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Attachment </td>
                            <td> <input type="file" id="attachment-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Links </td>
                            <td> <input type="text" id="links-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Percentage Change </td>
                            <td> <input type="text" id="percentage-change-input" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Tags </td>
                            <td> <input type="text" id="tag-input" />
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><button onClick={this.handlePost}  id="post-btn" type="button" className="btn btn-primary fa fa-envelope" >&nbsp;Post</button>
                            </td>
                        </tr>
                    </tbody>

                </table>
            </div>
        </div>);
    }

}

export default class Login extends React.Component {
    constructor(props) {
        super(props);
        this.state = { login: false, userName: '', password: '' ,isValid : true};
        this.handleSubmit = this.handleSubmit.bind(this);
        this.handleChangeUserName = this.handleChangeUserName.bind(this);
        this.handleChangePassword = this.handleChangePassword.bind(this);
    }
    handleSubmit() {
        let self = this;

        axios.get('src/rest/login.json')
            .then(function (response) {
                response.data.map((user)=>{
                    if(user.userName === self.state.userName && user.password === self.state.password ){
                        self.props.setLogin( true,user.role);
                        self.setState({isValid :true })
                    }else{
                        self.setState({isValid :false })
                    }
                });
            })
            .catch(function (error) {
                console.log(error);
            });
    }
    handleChangeUserName(event){
        this.setState({userName : event.target.value});
    }
     handleChangePassword(event){
        this.setState({password : event.target.value});
    }

    render() {
        return (
            <div className="email-class email-class-div login-cls">
                <div className="row row-login header-class">
                    <h3 className="float-class" >Login</h3>
                    <img src="src/img/star.png" className="float-class img-class" alt="Smiley face" height="35" width="35" />
                </div>
                <div className="error-div" style={{display : !this.state.isValid?'block':'none'}}>Invalid username or password</div>
                <div className="row row-login androidTextbox">
                    <input className="col-md-6" type="text" placeholder="User ID/Email" onChange={this.handleChangeUserName}/>
                </div>
                <div className="row row-login androidTextbox">
                    <input className="col-md-6" type="password" placeholder="Password" onChange={this.handleChangePassword} />
                </div>
                <div className="row row-login submit-row" onClick={this.handleSubmit}>
                    <div id="button" >SUBMIT</div>
                </div>
            </div>
        );
    }

}

答案 1 :(得分:0)

作为onCreateView参数列表的一部分,您会收到LayoutInflater inflater

拨打上述.inflate(R.layout.reg_book,container,false)变量的inflater