android - 为什么会出现此错误? “Syntax error on token ”实现“,@预期”

标签 android error-handling implementation

我在执行时遇到错误。该错误显示“ token “实现”的语法错误,@预期”。为什么会出现此错误,我该如何解决?

而且由于我是android新手,实现关键字有什么作用?

package com.fortuna.cinemalk;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.actionbarsherlock.ActionBarSherlock.Implementation;
import com.actionbarsherlock.app.ActionBar;
import com.fortuna.cinemalk.service.CommonVariable;
import com.fortuna.cinemalk.service.ScreenSizeIdentifier;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

public class MainActivity extends SlidingFragmentActivity {



    implements HeadlinesFragment.OnHeadlineSelectedListener{

        public void onArticleSelected(int position) {
            // The user selected the headline of an article from the HeadlinesFragment
            // Do something here to display that article

            NewsFramgment articleFrag = (NewsFramgment)
                    getSupportFragmentManager().findFragmentById(R.id.list);

            if (articleFrag != null) {
               System.out.print("no news found");

            } else {
                // Otherwise, we're in the one-pane layout and must swap frags...

                // Create fragment and give it an argument for the selected article
                NewsFramgment newFragment = new NewsFramgment();
                Bundle args = new Bundle();
                args.putInt(NewsFramgment.ARG_POSITION, position);
                newFragment.setArguments(args);

                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

                // Replace whatever is in the fragment_container view with this fragment,
                // and add the transaction to the back stack so the user can navigate back
                transaction.replace(R.id.content_frame, newFragment);
                transaction.addToBackStack(null);

                // Commit the transaction
                transaction.commit();
            }
        }

最佳答案

您收到语法错误:

public class MainActivity extends SlidingFragmentActivity {
    implements HeadlinesFragment.OnHeadlineSelectedListener{

应该:
public class MainActivity extends SlidingFragmentActivity implements HeadlinesFragment.OnHeadlineSelectedListener{

下次查看目录,查看导致问题的行号,这将大大缩小对语法错误的搜索范围。

关于android - 为什么会出现此错误? “Syntax error on token ”实现“,@预期”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25322442/

相关文章:

powershell - 在Powershell函数中忽略错误路径的问题

c++ - 为什么这个 Sieve of Sundaram 实现比这个 Sieve of Eratosthenes 实现快得多?

android - 在 Android 中更改抽屉导航标题图标图像

android - 了解 ACTION_MAIN

android - NdefRecord 崩溃是设备相关的

java - 实现扩展接口(interface) J 的接口(interface) I 的类 B 是否也扩展类型 I?

generics - 为什么具有 const 泛型 bool 值的方法不能调用为 true 和 false 都实现的方法?

java - 在for循环中初始化变量

swift - 无法构建模块

python - 您可以继续在运行时错误后运行代码吗?