试图在androidmanifest中声明类

时间:2017-10-11 23:29:45

标签: java android

我正在尝试在AndroidManifest.xml中声明我的活动。它不起作用,因为它说com.vakantielanden.quizapp.QuizResultaatFrankrijk is not public

当我尝试将我的课程公开时,会出现以下错误:Class 'QuizResultaatFrankrijk' is public, should be declared in a file name 'QuizResultaatFrankrijk.java'

那么我现在应该怎么做才能解决这个问题。提前谢谢!

这是我的AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vakantielanden.quizapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/applogo"
    android:label="VakantielandenQuiz"
    android:roundIcon="@mipmap/applogo"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".HomeActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".KeuzeActivity"></activity>
    <activity android:name=".QuizActivityFrankrijk"></activity>
    <activity android:name=".QuizActivitySpanje"></activity>
    <activity android:name=".QuizActivityItalie"></activity>
    <activity android:name=".QuizActivityDuitsland"></activity>
    <activity android:name=".QuizActivityNoorwegen"></activity>
    <activity android:name=".QuizActivityZweden"></activity>
    <activity android:name=".HighscoreActivity"></activity>

    <meta-data android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id" />
    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>

</application>


</manifest>

这是有问题的java代码:

class QuizResultaatFrankrijk extends AppCompatActivity {

TextView mFinalScoreFrankrijk;
Button mHomeButtonFrankrijk;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.result_quiz);

    mFinalScoreFrankrijk = (TextView)findViewById(R.id.scoreresultaat);
    mHomeButtonFrankrijk = (Button)findViewById(R.id.homepageknop);


    Bundle bundle = getIntent().getExtras();
    int score = bundle.getInt("finalScoreFrankrijk");

    mFinalScoreFrankrijk.setText( + score + "");


    mHomeButtonFrankrijk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(QuizResultaatFrankrijk.this, 
HomeActivity.class));
            QuizResultaatFrankrijk.this.finish();
        }
    });

}
} 

2 个答案:

答案 0 :(得分:1)

如果要创建Activity类,该类应该是公共的,该文件的名称也应该类似于Activity名称。

因此,您可能更改了Activity名称但未更改该活动所属的文件所以示例:
如果活动为MainActivity,则文件名为MainActivity.java
如果活动名称为QuizResultaatFrankrijk 那么文件名应为QuizResultaatFrankrijk.java
检查你的代码并解决它!

答案 1 :(得分:0)

复制这部分代码:

TextView mFinalScoreFrankrijk;
Button mHomeButtonFrankrijk;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.result_quiz);

    mFinalScoreFrankrijk = (TextView)findViewById(R.id.scoreresultaat);
    mHomeButtonFrankrijk = (Button)findViewById(R.id.homepageknop);


    Bundle bundle = getIntent().getExtras();
    int score = bundle.getInt("finalScoreFrankrijk");

    mFinalScoreFrankrijk.setText( + score + "");


    mHomeButtonFrankrijk.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(QuizResultaatFrankrijk.this, 
HomeActivity.class));
            QuizResultaatFrankrijk.this.finish();
        }
    });

}

删除文件,再次创建并再次粘贴代码。