gpt4 book ai didi

android - 启动驻留在单独库中的 Activity (Android)

转载 作者:行者123 更新时间:2023-11-29 00:36:35 28 4
gpt4 key购买 nike

我正在尝试从驻留在 android 库中的应用程序启动 Activity。当我尝试从应用程序启动 Activity 时,我不断收到以下异常。

09-07 12:26:35.300: E/AndroidRuntime(553): FATAL EXCEPTION: main
09-07 12:26:35.300: E/AndroidRuntime(553): java.lang.IllegalStateException: Could not execute method of the activity
09-07 12:26:35.300: E/AndroidRuntime(553): at android.view.View$1.onClick(View.java:3044)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.view.View.performClick(View.java:3511)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.view.View$PerformClick.run(View.java:14105)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.os.Handler.handleCallback(Handler.java:605)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.os.Handler.dispatchMessage(Handler.java:92)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.os.Looper.loop(Looper.java:137)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-07 12:26:35.300: E/AndroidRuntime(553): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 12:26:35.300: E/AndroidRuntime(553): at java.lang.reflect.Method.invoke(Method.java:511)
09-07 12:26:35.300: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-07 12:26:35.300: E/AndroidRuntime(553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-07 12:26:35.300: E/AndroidRuntime(553): at dalvik.system.NativeStart.main(Native Method)
09-07 12:26:35.300: E/AndroidRuntime(553): Caused by: java.lang.reflect.InvocationTargetException
09-07 12:26:35.300: E/AndroidRuntime(553): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 12:26:35.300: E/AndroidRuntime(553): at java.lang.reflect.Method.invoke(Method.java:511)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.view.View$1.onClick(View.java:3039)
09-07 12:26:35.300: E/AndroidRuntime(553): ... 11 more
09-07 12:26:35.300: E/AndroidRuntime(553): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.smarttech.androidlibrary.LibraryActivity.LAUNCH }
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.Activity.startActivityForResult(Activity.java:3190)
09-07 12:26:35.300: E/AndroidRuntime(553): at android.app.Activity.startActivity(Activity.java:3297)
09-07 12:26:35.300: E/AndroidRuntime(553): at com.smarttech.application.MainActivity.buttonLaunchActivity(MainActivity.java:25)
09-07 12:26:35.300: E/AndroidRuntime(553): ... 14 more

我在 Eclipse 中工作,我创建了两个项目 - 应用程序和库。

Library通过Properties->Android->Is Library声明为Android Library
应用通过Properties->Android->Add引用库。

我按照 Managing Projects from Eclipse with ADT 的说明进行操作.

图书馆:

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

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

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".LibraryActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="com.smarttech.androidlibrary.LibraryActivity.LAUNCH" />
</intent-filter>
</activity>
</application>
</manifest>

应用:

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

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


<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<activity android:name="com.smarttech.androidlibrary.LibraryActivity">
<intent-filter>
<action android:name="com.smarttech.androidlibrary.LibraryActivity.LAUNCH"/>
</intent-filter>
</activity>
</application>

</manifest>

--

package com.smarttech.application;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

public void buttonLaunchActivity(View view) {
Intent i = new Intent("com.smarttech.androidlibrary.LibraryActivity.LAUNCH");
startActivity(i);
}

}

最佳答案

这应该可行

public void buttonLaunchActivity(View view) {
Intent i = new Intent(this, LibraryActivity.class);
startActivity(i);
}

关于android - 启动驻留在单独库中的 Activity (Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12323768/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com