gpt4 book ai didi

android - 我无法从 jar 文件调用 Activity

转载 作者:行者123 更新时间:2023-11-30 03:42:07 24 4
gpt4 key购买 nike

我有这样的场景:我有一个包含 jar 文件的主项目(一个向主项目提供一些信息的辅助项目)。我按照这个 tuto 创建了 jar 文件然后将jar文件添加到/libs中的主项目中,然后将其添加到Build Path中。

当我从 jar 文件调用 Activity 时出现致命异常

这是日志

03-22 12:47:09.509: D/AndroidRuntime(13341): Shutting down VM
03-22 12:47:09.509: W/dalvikvm(13341): threadid=1: thread exiting with uncaught exception (group=0x40018578)
03-22 12:47:09.529: E/AndroidRuntime(13341): FATAL EXCEPTION: main
03-22 12:47:09.529: E/AndroidRuntime(13341): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.XXX.YYY/com.XXX.YYY.Subscription}; have you declared this activity in your AndroidManifest.xml?
03-22 12:47:09.529: E/AndroidRuntime(13341): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-22 12:47:09.529: E/AndroidRuntime(13341): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-22 12:47:09.529: E/AndroidRuntime(13341): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-22 12:47:09.529: E/AndroidRuntime(13341): at com.example.principal.Principal$1.onClick(Principal.java:40)
03-22 12:47:09.529: E/AndroidRuntime(13341): at android.view.View.performClick(View.java:2485)
03-22 12:47:09.529: E/AndroidRuntime(13341): at android.view.View$PerformClick.run(View.java:9080)
03-22 12:47:09.529: E/AndroidRuntime(13341): at android.os.Handler.handleCallback(Handler.java:587)
03-22 12:47:09.529: E/AndroidRuntime(13341): at android.os.Handler.dispatchMessage(Handler.java:92)
03-22 12:47:09.529: E/AndroidRuntime(13341): at android.os.Looper.loop(Looper.java:130)
03-22 12:47:09.529: E/AndroidRuntime(13341): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-22 12:47:09.529: E/AndroidRuntime(13341): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 12:47:09.529: E/AndroidRuntime(13341): at java.lang.reflect.Method.invoke(Method.java:507)
03-22 12:47:09.529: E/AndroidRuntime(13341): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
03-22 12:47:09.529: E/AndroidRuntime(13341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
03-22 12:47:09.529: E/AndroidRuntime(13341): at dalvik.system.NativeStart.main(Native Method)

这就是我在主项目中调用 Activity 的方式

final Intent intent = new Intent();

Button juego1Btn = (Button) findViewById(R.id.juego1Btn);

juego1Btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
/*Intent intent = new Intent(getBaseContext(), Subscription.class);
startActivity(intent);*/
intent.setAction(Intent.ACTION_MAIN);
intent.setClassName("com.XXX.YYY", "com.XXX.YYY.Subscription");
intent.putExtra("code", codigo);
intent.putExtra("keyword", keyword);
startActivityForResult(intent, 1);
}
});

这是 list

<activity
android:name="com.XXX.YYY.Subscription"
android:label="@string/app_name">
</activity>

知道为什么我有这个异常吗?

非常感谢!!!

最佳答案

首先,com.XXX.YYY.Subscription需要是 com.telecoming.sms_payment.Subscription ,如果您的代码值得相信。

其次,不要创建你的 Intent那样,作为你的<activity>不声称支持ACTION_MAIN .将您的代码替换为:

    Button juego1Btn = (Button) findViewById(R.id.juego1Btn);

juego1Btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(WhateverYourActivityClassIsWhereYouAreRightNow.this, Subscription.class);
intent.putExtra("code", codigo);
intent.putExtra("keyword", keyword);
startActivityForResult(intent, 1);
}
});

(将 WhateverYourActivityClassIsWhereYouAreRightNow 替换为此代码所在的 Activity 的名称)

关于android - 我无法从 jar 文件调用 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15569620/

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