是什么"&#39 ;;'预期"意思?

时间:2017-04-08 14:34:07

标签: java android

package com.example.myapplication;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

public class Pr_function_2_Activity extends AppCompatActivity {
    public static void main(String []args)
    {
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_pr_function_2_);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
        }
    }
}

这是错误消息。

  

C:\上传\ MyApplication2 \应用\ SRC \主\的java \ COM \示例\ MyApplication的\ Pr_function_2_Activity.java:14:   错误:';'预期           protected void onCreate(Bundle savedInstanceState)                                  ^ C:\ Upload \ MyApplication2 \ app \ src \ main \ java \ com \ example \ myapplication \ Pr_function_2_Activity.java:14:   错误:';'预期           protected void onCreate(Bundle savedInstanceState)

当我点击消息时,光标位于"protected void onCreate('here'Bundle savedInstanceState'here')"

为什么会出现错误? ;在声明结束时是必需的,不是吗?

无论如何我想解决这个错误。谢谢你的帮助。

2 个答案:

答案 0 :(得分:4)

您应该删除public static void main(String []args),这在Android中不需要。这就是编译器抱怨的原因,你将方法(onCreate)放在另一个方法中,你甚至不需要后者

答案 1 :(得分:0)

您不需要04-09 13:47:44.101 2576-2576/trebolete.keloke E/AndroidRuntime: FATAL EXCEPTION: main Process: trebolete.keloke, PID: 2576 java.lang.RuntimeException: Unable to start activity ComponentInfo{trebolete.keloke/trebolete.keloke.activities.PartyActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. at android.view.ViewGroup.addViewInner(ViewGroup.java:4309) at android.view.ViewGroup.addView(ViewGroup.java:4145) at android.view.ViewGroup.addView(ViewGroup.java:4117) at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:423) at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:404) at android.app.Activity.setContentView(Activity.java:2186) at trebolete.keloke.activities.PartyActivity.setParty(PartyActivity.java:52) at trebolete.keloke.activities.PartyActivity.onCreate(PartyActivity.java:33) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  ,因为它是Android Framework的一部分,您不需要明确定义它,它会映射到适当的活动。 main()用于android活动,onCreate()用于java程序。我希望在删除main()时错误消失。