Android 使用库活动作为主要活动
基本上,我想在我的最终应用程序中作为主/启动器运行我的一个库活动 例如: 库A包含一个名为DefaultMainActivity的活动,它有自己的布局和行为。此Android应用程序在Android属性中设置为库 应用程序B目前不包含任何活动,但实现了一些服务。此应用程序依赖于以前的库A。它已在Android属性中设置 在应用程序B中,我声明了以下活动: findViewById方法不断返回一个null对象,该对象抛出一个NPE 有办法解决这个问题吗 编辑:根据要求,这里是我活动的布局Android 使用库活动作为主要活动,android,android-activity,android-library,Android,Android Activity,Android Library,基本上,我想在我的最终应用程序中作为主/启动器运行我的一个库活动 例如: 库A包含一个名为DefaultMainActivity的活动,它有自己的布局和行为。此Android应用程序在Android属性中设置为库 应用程序B目前不包含任何活动,但实现了一些服务。此应用程序依赖于以前的库A。它已在Android属性中设置 在应用程序B中,我声明了以下活动: findViewById方法不断返回一个null对象,该对象抛出一个NPE 有办法解决这个问题吗 编辑:根据要求,这里是我活动的布局 清理并重
清理并重新启动Eclipse完成了任务。请发布DefaultMainActivity的布局。我已经更新了帖子。如果您发布的xml设置为DefaultMainActivity的内容视图,则不应引发NPE。我需要查看异常堆栈。该问题已自行修复。我不知道为什么,怎么,什么。但它是固定的
<activity android:name="com.libaray.a.DefaultMainActivity" android:launchMode="singleTop" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
layout_progress = (LinearLayout) findViewById(R.id.layout_progress);
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#DDDDDD">
<LinearLayout
android:id="@+id/layout_progress"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/text_progress"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:textStyle="bold"
android:textColor="#5283CF"
android:text="@string/misc_loading" />
</LinearLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_margin="50dp"
android:layout_above="@id/layout_progress"
android:layout_alignParentTop="true">
<ImageView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_centerInParent="true" />
</RelativeLayout>
<WebView
android:id="@+id/webview"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />
</RelativeLayout>