简体   繁体   中英

how to use classes from imported package in android

I have a package pkg1 which say I will import in pkg2.

secondactivity.java:
package seconddemoapp.demoapp.demo;
public class seconddemoappActivity extends Activity
{
 ----
}


firstactivity.java:
package firstdemo.firstdemoapp.demo;
import seconddemoapp.demoapp.demo.seconddemoappActivity;

public class firstactivity extends Activity
 {
------
Intent i = new Intent(firstactivity.this, seconddemoappActivity.class); 
startActivity(i); 
}

I am getting "NoClassDefFoundError" for seconddemoappActivity.class

Where am I going wrong? How can I use the seconddemoactivity class in the firstactivity ?

i think u miss activity declaration in your manifest file....

 <activity
 android:label="@string/app_name"
                android:name="seconddemoapp.demoapp.demo.seconddemoappActivity"
                </activity>

It is not a packaging issue, because you are getting an exception at runtime. It means your code should have compiled correctly. This means import of packaging is correct, but the Virtual machine cannot load the class file at runtime.

In your case I think that Activity is running in a different process that is why it cannot be loaded and you are receiving an exception. Or it is not running/loaded at all.

If you recently updated ADT, there have been some changes to the way classes are exported which may have led to this message. Check out this post:

http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17

As mentioned you should also make sure you put your new activity in the manifest file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM