【问题标题】:(error: class, interface, or enum expected) this error showed up 15 times(error: class, interface, or enum expected) 这个错误出现了 15 次
【发布时间】:2015-06-16 18:16:18
【问题描述】:

这是我看newboston系列时做的TopSectionFragment的代码

package com.example.rohanmarwaha.memecreator;

import android.os.Bundle;
import android.app.Fragment;
import android.support.annotation.Nullable;
import android.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.app.Activity;
import android.widget.Button;
import android.widget.EditText;
import java.util.zip.Inflater;

public class TopSectionFragment extends Fragment {

    private static EditText toptextinput;
    private static EditText bottomtextinput;

    TopSectionListener activitycommander;

    public interface TopSectionListener {
        public void creatememe(String top, String bottom);
    }
}@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {
        activitycommander = (TopSectionListener) activity
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString());
    }

}



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

    toptextinput = (EditText) veiw.FindViewById(R.id.bottomfragment);
    bottomtextinput = (EditText) view.FindViewById(R.id.bottomtextinput);
    final button = (Button) view.FindViewById(R.id.button);

    button.setOnClickListener(
    new View.OnClickListener() {
        public void onClick(View v) {

            buttonClicked(v);
        }
    });

    return view;

    public void buttonClicked(View view) {
        actioncommander.creatememe(toptextinput.getText().toString(), bottomtextinput.getText().toString())
    }

}

我有 15 次(错误:类、接口或枚举预期)错误。我是android应用程序开发的新手。请帮助!!

【问题讨论】:

  • 你在接口声明后关闭了片段

标签: android android-fragments android-fragmentactivity


【解决方案1】:

你在你的方法之前关闭了你的课程。

只需更改此行

}@Override
public void onAttach(Activity activity) {

到这里

@Override
public void onAttach(Activity activity) {

【讨论】:

    猜你喜欢
    • 2020-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多