This question already has answers here:
launch activities from different package
                                
                                    (5个答案)
                                
                        
                                6年前关闭。
            
                    
最近,我一直在研究一个新的应用程序,我正在尝试使用意图向其添加插件。

我创建了一个名为DLC的小型插件应用程序,当我单击按钮时,我试图从名为DLC的主应用程序中启动MinePedia中的活动。

为此,我创建了一个调用DLC中的活动的意图,但是每当我单击按钮时,都会出现一个Class not found to handle intent错误。

谁能帮我解决这个问题?

DLC中的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dlc"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="10" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:logo="@drawable/ic_launcher">
               <action android:name="com.dlc.MainActivity" />

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


    </application>

</manifest>


MainActivity(MinePedia)

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

     Button button2 = (Button) findViewById(R.id.button1);
        button2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(getApplicationContext(), MainActivity2.class));

            }
        });




        Button button9 = (Button) findViewById(R.id.info);
        button9.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(getApplicationContext(), AppInf.class));

            }
        });




        Button button91 = (Button) findViewById(R.id.dlc);
        button91.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                Intent i=new Intent("com.dlc.MainActivity.class"); startActivity(i);
            }
        });






        Button button96 = (Button) findViewById(R.id.help);
        button96.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                startActivity(new Intent(getApplicationContext(), Instruction.class));

            }
        });



        // this
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

        int icon = R.drawable.launcher;
        CharSequence tickerText = "MinecraftPedia"; // ticker-text
        long when = System.currentTimeMillis();
        Context context = getApplicationContext();
        CharSequence contentTitle = "MinePedia";
        CharSequence contentText = "This is the quick launch button for MinePedia";
        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        Notification notification = new Notification(icon, tickerText, when);
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

        // and this
        final int HELLO_ID = 1;
        mNotificationManager.notify(HELLO_ID, notification);

}


LOGCAT

08-17 02:39:26.573: E/AndroidRuntime(912): FATAL EXCEPTION: main
08-17 02:39:26.573: E/AndroidRuntime(912): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.dlc.MainActivity.class }
08-17 02:39:26.573: E/AndroidRuntime(912):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
08-17 02:39:26.573: E/AndroidRuntime(912):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
08-17 02:39:26.573: E/AndroidRuntime(912):  at android.app.Activity.startActivityForResult(Activity.java:3370)
08-17 02:39:26.573: E/AndroidRuntime(912):  at android.app.Activity.startActivityForResult(Activity.java:3331)
08-17 02:39:26.573: E/AndroidRuntime(912):  at android.app.Activity.startActivity(Activity.java:3566)
08-17 02:39:26.573: E/AndroidRuntime(912):  at android.app.Activity.startActivity(Activity.java:3534)
08-17 02:39:26.573: E/AndroidRuntime(912):  at com.shadycorp.minecraftrecipebook.MainActivity$3.onClick(MainActivity.java:59)
08-17 02:39:26.573: E/AndroidRuntime(912):  at android.view.View.performClick(View.java:4202)
08-17 02:39:26.573: E/AndroidRuntime(912):  at android.view.View$PerformClick.run(View.java:17340)

最佳答案

显然,您正在尝试打开其他程序包中的活动。有关实际操作方法,请参见以下链接的答案:
launch activities from different package

关于android - Android程式设计(找不到处理 Intent 异常的类别)错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15860843/

10-10 09:57