[英]How to run class activity in jar file in Android?
I'm new in Android, I've had some problems 我是Android新手,遇到了一些问题
I have 2 package: 我有2个包裹:
I export the first package into jar file a and then I add to the second package as library. 我将第一个包导出到jar文件a中,然后将第二个包作为库添加到第二个包中。 I do like this:
我喜欢这样:
the second package import like this: 第二个包导入是这样的:
import fr.keuse.rightsalert.activity.ApplistActivity;
and here is the problem code when I call class in jar file (throwing a Nullpoiterexception
这是我在jar文件中调用类时的问题代码(
Nullpoiterexception
private OnItemClickListener listlistener = new OnItemClickListener() {
@Override
public void onItemClick(@SuppressWarnings("rawtypes") AdapterView parent, View arg1, int position,long arg3) {
//Toast.makeText(getApplicationContext(), "You have clicked on" + position +((Order)parent.getItemAtPosition(position)).getOrderName(), Toast.LENGTH_SHORT).show();
//------------show new intent when clicked-----------------
switch (position){
case 0:
**new fr.keuse.rightsalert.activity.ApplistActivity();
Intent i = new Intent(System_app.this,ApplistActivity.class);
startActivity(i);**
break;
case 1:
Toast.makeText(getApplicationContext(), "You have clicked on number 2", Toast.LENGTH_SHORT).show();
break;
}
}
};
Don't do this: 不要这样做:
new fr.keuse.rightsalert.activity.ApplistActivity();
You don't instantiate activities like this. 您不会实例化此类活动。 All you need to do to start an activity is this:
开始活动所需要做的就是:
Intent i = new Intent(System_app.this,ApplistActivity.class);
startActivity(i);
Android will instantiate the activity for you. Android将为您实例化活动。
Make sure that you have not defined a constructor for ApplistActivity
. 确保尚未定义
ApplistActivity
的构造ApplistActivity
。 Make sure that you have a method onCreate()
in ApplistActivity
. 确保您在
ApplistActivity
具有onCreate()
方法。 Make sure that you have this activity listed in your AndroidManifest.xml. 确保您的AndroidManifest.xml中列出了此活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.