请问如何在Android中引用我的其他包中的其他类?
我有我的主包。在那之下它有几个子包。 如何将子包下的那些类引用到主包中的主类中?
我所做的是,在主类中,我通过 Intent 调用子包中的类。 到目前为止,这是我尝试过但无济于事的方法:
case 0:
Intent acorn = new Intent( "com.fps.iHealthFirst.vegetables.AcornSquash.class" );
//Intent acorn = new Intent( Nutritional_List.this, AcornSquash.class );
startActivity( acorn );
break;
我很难做到这一点。感谢您的帮助。
顺便说一句,这是 logcat:
10-22 23:13:03.585: E/AndroidRuntime(395): FATAL EXCEPTION: main
10-22 23:13:03.585: E/AndroidRuntime(395): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.fps.iHealthFirst/com.fps.iHealthFirst.vegetables.AcornSquash}; have you declared this activity in your AndroidManifest.xml?
另外,我在 list 文件中编辑了这个:
<activity android:exported="false"
android:name=".vegetables.AcornSquashAcornSquash"
android:label="@string/inutrition" >
<intent-filter >
<action android:name="com.fps.iHealthFirst.vegetables.ACORNSQUASH" />
</intent-filter>
</activity>
最佳答案
这是你应该做的:
import com.fps.iHealthFirst.vegetables.AcornSquash;
Intent acorn = new Intent(this, AcornSquash.class);
startActivity(acorn);
更新:
您必须在 Manifest.xml 中声明所有 Activity 。保持简单:
<activity
android:name="com.fps.iHealthFirst.vegetables.AcornSquash"
android:label="@string/some_name" >
</activity>
最后,确保您的文件夹结构与您的包路径一致,即您的文件 AcornSquash.java
必须位于 src/com/fps/iHealthFirst/vegetables/
文件夹。
关于android - 如何从Android中的其他包中引用类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13014110/