android.content.ActivityNotFoundException:找不到处理Intent的Activity {act = com.application.bpjs.AnathorActivity}

时间:2014-12-09 16:07:43

标签: java android

我的程序有问题,我想链接到不同的布局,但我的代码不起作用。

这是我的代码

MainActivity.java

package com.application.bpjs;

//import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
//import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {
Button imgBtnKlinik;
Button imgBtnPuskesmas;
Button imgBtnRS;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        //imgBtnKlinik = (Button)findViewById(R.id.klinik);
        imgBtnPuskesmas = (Button)findViewById(R.id.puskesmas);
        imgBtnRS = (Button)findViewById(R.id.rs);

        OnClickListener listener = new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent("com.application.bpjs.AnathorActivity");
                startActivity(intent);
            }
        };
        imgBtnKlinik = (Button)findViewById(R.id.klinik);
        imgBtnKlinik.setOnClickListener(listener);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    /**@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }*/
}

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.application.bpjs"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.application.bpjs.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity 
            android:name="com.application.bpjs.AnathorActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

AnathorActivity.java

package com.application.bpjs;

import java.security.PublicKey;

import android.app.Activity;
import android.os.Bundle;
public class AnathorActivity extends Activity{
    protected void OnCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
}

这是我的代码,我代码的问题是

OnClickListener listener = new OnClickListener() {

 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 Intent intent = new Intent("com.application.bpjs.AnathorActivity");
 startActivity(intent);

我的错误

12-09 23:33:27.012: E/AndroidRuntime(32299): FATAL EXCEPTION: main
12-09 23:33:27.012: E/AndroidRuntime(32299): Process: com.application.bpjs, PID: 32299
12-09 23:33:27.012: E/AndroidRuntime(32299): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.application.bpjs/com.application.bpjs.AnathorActivity}; have you declared this activity in your AndroidManifest.xml?
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.app.Activity.startActivityForResult(Activity.java:3424)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.app.Activity.startActivityForResult(Activity.java:3385)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.app.Activity.startActivity(Activity.java:3627)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.app.Activity.startActivity(Activity.java:3595)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at com.application.bpjs.MainActivity$1.onClick(MainActivity.java:37)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.view.View.performClick(View.java:4445)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.view.View$PerformClick.run(View.java:18446)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.os.Handler.handleCallback(Handler.java:733)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.os.Handler.dispatchMessage(Handler.java:95)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.os.Looper.loop(Looper.java:136)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at android.app.ActivityThread.main(ActivityThread.java:5111)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at java.lang.reflect.Method.invokeNative(Native Method)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at java.lang.reflect.Method.invoke(Method.java:515)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
12-09 23:33:27.012: E/AndroidRuntime(32299):    at dalvik.system.NativeStart.main(Native Method)

感谢名单

2 个答案:

答案 0 :(得分:1)

您错过了在manifest.xml文件中声明AnathorActivity活动。

<activity
        android:name=".AnathorActivity"
        android:label="@string/app_name" >
</activity>

答案 1 :(得分:0)

在按钮onClick方法中尝试此代码:

Intent intent = new Intent(MainActivity.this,AnathorActivity.class);
startActivity(intent);