点击

时间:2015-09-01 17:08:15

标签: android button android-studio

当我点击菜单按钮时,我想返回主菜单,即应用程序启动的活动。必须遵循app.mobiledevicesecurity部分的内容?我以为它一定是起始级的名字?我是android studio开发的新手。任何帮助将不胜感激。

Logcat详细信息:

09-01 19:02:04.755    1988-1988/app.mobiledevicesecurity E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: app.mobiledevicesecurity, PID: 1988
    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=app.mobiledevicesecurity.MainActivity }
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1781)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501)
            at android.app.Activity.startActivityForResult(Activity.java:3745)
            at android.app.Activity.startActivityForResult(Activity.java:3706)
            at android.app.Activity.startActivity(Activity.java:4016)
            at android.app.Activity.startActivity(Activity.java:3984)
            at app.mobiledevicesecurity.Result$2.onClick(Result.java:46)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Result.java:

package app.mobiledevicesecurity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Result extends Activity
{
    private static Button playbtn;
    private static Button menubutton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        OnClickPlayButtonListener();
        OnClickMenuButtonListener();
        TextView textResult = (TextView) findViewById(R.id.textResult);
        Bundle b = getIntent().getExtras();
        int score = b.getInt("score");
        textResult.setText("You scored" + " " + score + " for the quiz.");
    }

    public void OnClickPlayButtonListener() {
        playbtn = (Button) findViewById(R.id.btn);
        playbtn.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent("app.mobiledevicesecurity.Quiz");
                        startActivity(intent);
                    }
                }
        );
    }

    public void OnClickMenuButtonListener() {
        menubutton = (Button) findViewById(R.id.menubtn);
        menubutton.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent("app.mobiledevicesecurity.MainActivity");
                        startActivity(intent);
                    }
                }
        );
    }


}

有关我必须替换MainActivity文本的任何建议吗?

1 个答案:

答案 0 :(得分:0)

试着像这样:

public void onClick(View v) {
    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
    startActivity(intent);
}

这适合我...