【问题标题】:Why do i get this error? "Syntax error on token "implements", @ expected"为什么我会收到此错误? “令牌“实现”的语法错误,@预期”
【发布时间】:2014-08-15 07:01:32
【问题描述】:

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

由于我是 android 新手,因此 implementation 关键字有什么作用?

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();
            }
        }

【问题讨论】:

  • extends SlidingFragmentActivity 之后删除{。至于“实现关键字是做什么的?”,请阅读What is an interface?

标签: android error-handling implementation


【解决方案1】:

您遇到了语法错误:

public class MainActivity extends SlidingFragmentActivity {
    implements HeadlinesFragment.OnHeadlineSelectedListener{

应该是:

public class MainActivity extends SlidingFragmentActivity implements HeadlinesFragment.OnHeadlineSelectedListener{

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-14
    • 2021-04-30
    • 2013-07-16
    • 2020-09-04
    • 2022-01-23
    • 1970-01-01
    • 2021-06-20
    • 1970-01-01
    相关资源
    最近更新 更多