gpt4 book ai didi

android - 在android中集成两个包

转载 作者:行者123 更新时间:2023-11-29 02:06:35 25 4
gpt4 key购买 nike

我有两个包 com.android.package1 和 com.android.package2
package1 中的 Activity (比如 A)想要启动 package2 中的 Activity (比如 B)
为此,我使用了以下方法

Intent to_start_B = new Intent(A.this,com.android.Package2.B.class);
startActivity(to_start_B);

这对其他 Activity 很好,除了这个(所以 list 和调用没有问题)!!

此特定 Activity B 的代码是

public class B extends Activity {
private Logger logger = Logger.getMyLogger(this.getClass().getName());

private MicroRuntimeServiceBinder microRuntimeServiceBinder;
private ServiceConnection serviceConnection;

static final int CHAT_REQUEST = 0;
static final int SETTINGS_REQUEST = 1;

private MyReceiver myReceiver;
private MyHandler myHandler;

private TextView infoTextView;
private static String nickname="";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

myReceiver = new MyReceiver();

IntentFilter killFilter = new IntentFilter();
killFilter.addAction("jade.demo.chat.KILL");
registerReceiver(myReceiver, killFilter);

IntentFilter showChatFilter = new IntentFilter();
showChatFilter.addAction("jade.demo.chat.SHOW_CHAT");
registerReceiver(myReceiver, showChatFilter);

myHandler = new MyHandler();
nickname = "Ganesh";//getIntent().getExtras().getString("uname");

setContentView(R.layout.chat_main);
Button button = (Button) findViewById(R.id.btn_chatroom);
button.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
if (!checkName(nickname)) {
logger.info("Invalid nickname!");
myHandler.postError(getString(R.string.msg_nickname_not_valid));
} else {
try {
SharedPreferences settings = getSharedPreferences(
"jadeChatPrefsFile", 0);
String host = settings.getString("defaultHost", "");
String port = settings.getString("defaultPort", "");
infoTextView.setText(getString(R.string.msg_connecting_to)
+ " " + host + ":" + port + "...");
startChat(nickname, host, port, agentStartupCallback);
} catch (Exception ex) {
logger.severe("Unexpected exception creating chat agent!");
infoTextView.setText(getString(R.string.msg_unexpected));
}
}

}
});
infoTextView = (TextView) findViewById(R.id.infoTextView);
infoTextView.setText("");

}

我在以下方式中遇到错误

03-07 11:36:25.399: W/dalvikvm(8493): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-07 11:36:25.409: E/AndroidRuntime(8493): FATAL EXCEPTION: main
03-07 11:36:25.409: E/AndroidRuntime(8493): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.home/chat.client.gui.MainActivity}: java.lang.NullPointerException
03-07 11:36:25.409: E/AndroidRuntime(8493): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-07 11:36:25.409: E/AndroidRuntime(8493): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-07 11:36:25.409: E/AndroidRuntime(8493): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-07 11:36:25.409: E/AndroidRuntime(8493): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-07 11:36:25.409: E/AndroidRuntime(8493): at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 11:36:25.409: E/AndroidRuntime(8493): at android.os.Looper.loop(Looper.java:123)
03-07 11:36:25.409: E/AndroidRuntime(8493): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-07 11:36:25.409: E/AndroidRuntime(8493): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 11:36:25.409: E/AndroidRuntime(8493): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 11:36:25.409: E/AndroidRuntime(8493): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-07 11:36:25.409: E/AndroidRuntime(8493): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-07 11:36:25.409: E/AndroidRuntime(8493): at dalvik.system.NativeStart.main(Native Method)
03-07 11:36:25.409: E/AndroidRuntime(8493): Caused by: java.lang.NullPointerException
03-07 11:36:25.409: E/AndroidRuntime(8493): at chat.client.gui.MainActivity.onCreate(MainActivity.java:96)
03-07 11:36:25.409: E/AndroidRuntime(8493): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-07 11:36:25.409: E/AndroidRuntime(8493): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-07 11:36:25.409: E/AndroidRuntime(8493): ... 11 more

所以基本上它的问题只与特定 Activity B 相关。但如果它作为另一个应用程序的一部分执行,它就可以正常工作!

谁能告诉我如何解决这个问题?

最佳答案

嘿,找到了解决我问题的方法

在集成来自不同项目的两个包时,我从 src 和 gen 文件夹(连同布局)拖放了包。
所以我有两份 R 文件。但是 pakage2.R 文件无效,因为新的 R 文件是为 Package1 中的每个组件(在 gen 文件夹中)自动生成的,其中包含新的 R.id所以解决方案是

  1. 从 gen 文件夹中删除 Package2。
  2. 在Package2的每个文件中导入Package1.R文件

关于android - 在android中集成两个包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9724302/

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