android系统中有一个例外classcast同时使用所有MyApplication类 [英] Having a classcast exception in android while using MyApplication class
问题描述
我在做什么 ::我想使用所有MyApplication类将数据发送到下一个活动。
的问题,我现在面临 ::有类转换异常
BLD_IndividualListOfItems_Starters.java
公共类BLD_IndividualListOfItems_Starters延伸活动{
//声明变量
的JSONObject的JSONObject;
JSONArray jsonarray;
ListView控件列表视图;
ListViewAdapterForAtomicListItemtype适配器;
ProgressDialog mProgressDialog;
ArrayList的<&HashMap的LT;字符串,字符串>> ArrayList的;
静态字符串NAME =等级;
按钮BTN; 串TYPE_FILTER; StringBuilder的结果;
所有MyApplication mApplication; @覆盖
公共无效的onCreate(捆绑savedInstanceState){ super.onCreate(savedInstanceState); mApplication =(所有MyApplication)getApplication();
//从listview_main.xml视图
的setContentView(R.layout.listview_main); TYPE_FILTER = getIntent()getExtras()的getString(key_title)。。
Log.v(----价值开始---,TYPE_FILTER);
//定位listview_main.xml列表视图
列表视图=(ListView控件)findViewById(R.id.listview); BTN =(按钮)findViewById(R.id.button1);
btn.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根 结果=新的StringBuilder();
的for(int i = 0; I< arraylist.size();我++){
如果(adapter.mysparse.get(我)==真){ result.append(arraylist.get(I)获得(BLD_IndividualListOfItems_Starters.NAME));
result.append(\\ n);
} }
意图N =新意图(BLD_IndividualListOfItems_Starters.this,ResultActivity.class);
n.putExtra(缓冲,result.toString());
startActivity(N);
}
}); //执行DownloadJSON的AsyncTask
新DownloadJSON()执行();
} // DownloadJSON的AsyncTask
私有类DownloadJSON扩展的AsyncTask<太虚,太虚,太虚> { @覆盖
在preExecute保护无效(){
super.on preExecute();
//创建一个progressdialog
mProgressDialog =新ProgressDialog(BLD_IndividualListOfItems_Starters.this);
//设置progressdialog称号
//mProgressDialog.setTitle(\"Fetching信息);
//设置progressdialog消息
mProgressDialog.setMessage(正在加载...);
mProgressDialog.setIndeterminate(假);
//显示progressdialog
mProgressDialog.show();
} @覆盖
保护无效doInBackground(虚空...... PARAMS){
//创建一个数组
ArrayList的=新的ArrayList<&HashMap的LT;字符串,字符串>>(); 字符串NEWURL =? +键=+ TYPE_FILTER;
//从给定的URL地址JSON对象
的JSONObject = JSONfunctions.getJSONfromURL(http://54.218.73.244:7005/RestaurantAtomicListItemType/+ NEWURL); 尝试{
//找到在JSON数组名
jsonarray = jsonobject.getJSONArray(餐馆); 的for(int i = 0; I< jsonarray.length();我++){
HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>();
的JSONObject = jsonarray.getJSONObject(ⅰ);
// Retrive JSON对象
map.put(BLD_IndividualListOfItems_Starters.NAME,jsonobject.getString(MasterListMenuName)); //设置JSON对象到数组
arraylist.add(地图);
}
}赶上(JSONException E){
Log.e(错误,e.getMessage());
e.printStackTrace();
}
返回null;
} @覆盖
保护无效onPostExecute(无效参数){
//将结果传递到ListViewAdapter.java
适配器=新ListViewAdapterForAtomicListItemtype(BLD_IndividualListOfItems_Starters.this,ArrayList的);
//适配器设置到ListView mApplication.setArrayListMapData(数组列表); listview.setAdapter(适配器);
//关闭progressdialog
mProgressDialog.dismiss();
}
}
}
ResultActivity.java
公共类ResultActivity扩展ListActivity { ListView的lstView;
ArrayList的<&HashMap的LT;字符串,字符串>> ArrayList的=新的ArrayList<&HashMap的LT;字符串,字符串>>();
串MYNAME;
所有MyApplication mApplication; @覆盖
保护无效的onCreate(捆绑savedInstanceState){ super.onCreate(savedInstanceState);
的for(int i = 0;我小于10;我++)
{
HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>();
map.put(键,值+ I);
arraylist.add(地图); } 的String [] =从{钥匙};
INT []为= {} R.id.textView1;
SimpleAdapter适配器=新SimpleAdapter(这一点,ArrayList中,R.layout.custom_single_list,从,到);
setListAdapter(适配器); }}
清单
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.multitabcheckboxselection
安卓版code =1
机器人:=的versionName1.0> <用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =18/> <使用许可权的android:NAME =android.permission.INTERNET对/> <应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名字=com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters/>
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_MainCourse/>
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_SideCourse/>
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Others/>
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Desert/>
<活动机器人:名字=com.example.multitabcheckboxselection.ResultActivity/>
< /用途>
<应用
机器人:名字=com.android.app.MyApplication
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME>
< /用途>< /清单>
ListViewAdapterForAtomicListItemtype.java
公共类ListViewAdapterForAtomicListItemtype扩展BaseAdapter实现OnCheckedChangeListener { //声明变量
上下文语境;
LayoutInflater吹气;
ArrayList的<&HashMap的LT;字符串,字符串>>数据;
HashMap的<字符串,字符串> resultp =新的HashMap<字符串,字符串>();
SparseBooleanArray mysparse; 公共ListViewAdapterForAtomicListItemtype(上下文的背景下,
ArrayList的<&HashMap的LT;字符串,字符串>>数组列表){
this.context =背景;
数据=数组列表;
mysparse =新SparseBooleanArray(data.size());
} @覆盖
公众诠释的getCount(){
返回data.size();
} @覆盖
公共对象的getItem(INT位置){
返回null;
} @覆盖
众长getItemId(INT位置){
返回0;
} 公共查看getView(最终诠释的立场,观点convertView,父母的ViewGroup){
//声明变量
TextView的名称;
复选框CHK; 吹气=(LayoutInflater)上下文
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 查看ItemView控件= inflater.inflate(R.layout.listview_item_for_atomic_list_item_type,父母,假);
//获取位置
resultp = data.get(位置); //定位listview_item.xml的TextViews
名字=(TextView中)itemView.findViewById(R.id.textView_id_atomic_list_item_type);
CHK =(复选框)itemView.findViewById(R.id.checkBox_atomic_list_item_type_id);
//捕捉位置,并设置结果向TextViews
name.setText(resultp.get(BLD_IndividualListOfItems_Starters.NAME)); chk.setTag(位置);
chk.setChecked(mysparse.get(位置,FALSE));
chk.setOnCheckedChangeListener(本); 返回ItemView控件;
} 公共布尔器isChecked(INT位置){
返回mysparse.get(位置,FALSE);
} 公共无效setChecked(INT位置,布尔器isChecked){
mysparse.put(位置,器isChecked); } 公共无效切换(INT位置){
setChecked(位置,器isChecked(位置)!); } @覆盖
公共无效onCheckedChanged(CompoundButton buttonView,布尔器isChecked){
// TODO自动生成方法存根
mysparse.put((整数)buttonView.getTag(),器isChecked);
}
}
登录:
13 01-03:30:12.828:D / AndroidRuntime(461):关闭VM
01-03 13:30:12.828:W / dalvikvm(461):主题ID = 1:螺纹未捕获的异常退出(组= 0x4001d800)
01-03 13:30:12.868:E / AndroidRuntime(461):致命异常:主要
01-03 13:30:12.868:E / AndroidRuntime(461):了java.lang.RuntimeException:无法启动活动ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems}:了java.lang.RuntimeException:无法启动活动ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters}: java.lang.ClassCastException:android.app.Application
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.os.Handler.dispatchMessage(Handler.java:99)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.os.Looper.loop(Looper.java:123)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.ActivityThread.main(ActivityThread.java:4627)
01-03 13:30:12.868:E / AndroidRuntime(461):在java.lang.reflect.Method.invokeNative(本机方法)
01-03 13:30:12.868:E / AndroidRuntime(461):在java.lang.reflect.Method.invoke(Method.java:521)
01-03 13:30:12.868:E / AndroidRuntime(461):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
01-03 13:30:12.868:E / AndroidRuntime(461):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-03 13:30:12.868:E / AndroidRuntime(461):在dalvik.system.NativeStart.main(本机方法)
01-03 13:30:12.868:E / AndroidRuntime(461):了java.lang.RuntimeException:产生的原因无法启动活动ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters}: java.lang.ClassCastException:android.app.Application
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.widget.TabHost $ IntentContentStrategy.getContentView(TabHost.java:651)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.widget.TabHost.setCurrentTab(TabHost.java:323)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.widget.TabHost.addTab(TabHost.java:213)
01-03 13:30:12.868:E / AndroidRuntime(461):在com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems.onCreate(BreakfastLunchDinnerIndividualListOfItems.java:36)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-03 13:30:12.868:E / AndroidRuntime(461):11 ...更多
01-03 13:30:12.868:E / AndroidRuntime(461):java.lang.ClassCastException:产生的原因android.app.Application
01-03 13:30:12.868:E / AndroidRuntime(461):在com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters.onCreate(BLD_IndividualListOfItems_Starters.java:47)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-03 13:30:12.868:E / AndroidRuntime(461):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-03 13:30:12.868:E / AndroidRuntime(461):20 ...更多
01-03 13:30:15.563:I /流程(461):发送信号。 PID:461 SIG:9
{编辑}
BLD_IndividualListOfItems_Starters.java
公共类BLD_IndividualListOfItems_Starters延伸活动{
//声明变量
的JSONObject的JSONObject;
JSONArray jsonarray;
ListView控件列表视图;
ListViewAdapterForAtomicListItemtype适配器;
ProgressDialog mProgressDialog;
ArrayList的<&HashMap的LT;字符串,字符串>> ArrayList的;
静态字符串NAME =等级;
按钮BTN; 串TYPE_FILTER; StringBuilder的结果;
所有MyApplication mApplication; @覆盖
公共无效的onCreate(捆绑savedInstanceState){ super.onCreate(savedInstanceState); mApplication =(所有MyApplication)getApplicationContext();
//从listview_main.xml视图
的setContentView(R.layout.listview_main); TYPE_FILTER = getIntent()getExtras()的getString(key_title)。。
Log.v(----价值开始---,TYPE_FILTER);
//定位listview_main.xml列表视图
列表视图=(ListView控件)findViewById(R.id.listview); BTN =(按钮)findViewById(R.id.button1);
btn.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根 结果=新的StringBuilder();
的for(int i = 0; I< arraylist.size();我++){
如果(adapter.mysparse.get(我)==真){ result.append(arraylist.get(I)获得(BLD_IndividualListOfItems_Starters.NAME));
result.append(\\ n);
} }
意图N =新意图(BLD_IndividualListOfItems_Starters.this,ResultActivity.class);
n.putExtra(缓冲,result.toString());
startActivity(N);
}
}); //执行DownloadJSON的AsyncTask
新DownloadJSON()执行();
} // DownloadJSON的AsyncTask
私有类DownloadJSON扩展的AsyncTask<太虚,太虚,太虚> { @覆盖
在preExecute保护无效(){
super.on preExecute();
//创建一个progressdialog
mProgressDialog =新ProgressDialog(BLD_IndividualListOfItems_Starters.this);
//设置progressdialog称号
//mProgressDialog.setTitle(\"Fetching信息);
//设置progressdialog消息
mProgressDialog.setMessage(正在加载...);
mProgressDialog.setIndeterminate(假);
//显示progressdialog
mProgressDialog.show();
} @覆盖
保护无效doInBackground(虚空...... PARAMS){
//创建一个数组
ArrayList的=新的ArrayList<&HashMap的LT;字符串,字符串>>(); 字符串NEWURL =? +键=+ TYPE_FILTER;
//从给定的URL地址JSON对象
的JSONObject = JSONfunctions.getJSONfromURL(http://54.218.73.244:7005/RestaurantAtomicListItemType/+ NEWURL); 尝试{
//找到在JSON数组名
jsonarray = jsonobject.getJSONArray(餐馆); 的for(int i = 0; I< jsonarray.length();我++){
HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>();
的JSONObject = jsonarray.getJSONObject(ⅰ);
// Retrive JSON对象
map.put(BLD_IndividualListOfItems_Starters.NAME,jsonobject.getString(MasterListMenuName)); //设置JSON对象到数组
arraylist.add(地图);
}
}赶上(JSONException E){
Log.e(错误,e.getMessage());
e.printStackTrace();
}
返回null;
} @覆盖
保护无效onPostExecute(无效参数){
//将结果传递到ListViewAdapter.java
适配器=新ListViewAdapterForAtomicListItemtype(BLD_IndividualListOfItems_Starters.this,ArrayList的);
//适配器设置到ListView mApplication.setArrayListMapData(数组列表); listview.setAdapter(适配器);
//关闭progressdialog
mProgressDialog.dismiss();
}
}
}
MyApplication.java
包com.example.multitabcheckboxselection;进口的java.util.ArrayList;
进口的java.util.HashMap;进口android.app.Application;公共类MyApplication的扩展应用{ ArrayList的<&HashMap的LT;字符串,字符串>> ArrayList的; @覆盖
公共无效的onCreate(){ super.onCreate();
} 公共无效setArrayListMapData(ArrayList的<&HashMap的LT;字符串,字符串>>使用setData)
{
ArrayList的使用setData =;
} 公众的ArrayList<&HashMap的LT;字符串,字符串>> getArrayListMapData()
{
返回数组列表;
}
}
{编辑-3}
清单
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.multitabcheckboxselection
安卓版code =1
机器人:=的versionName1.0> <用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =18/> <使用许可权的android:NAME =android.permission.INTERNET对/> <应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名字=com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters/>
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_MainCourse/>
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_SideCourse/>
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Others/>
<活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Desert/>
<活动机器人:名字=com.example.multitabcheckboxselection.ResultActivity/>
< /用途>
<应用
机器人:allowBackup =真
机器人:名字=com.example.multitabcheckboxselection.MyApplication
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME>
< /用途>< /清单>
MyApplication.java
包com.example.multitabcheckboxselection;进口的java.util.ArrayList;
进口的java.util.HashMap;进口android.app.Application;公共类MyApplication的扩展应用{ ArrayList的<&HashMap的LT;字符串,字符串>> ArrayList的; @覆盖
公共无效的onCreate(){ super.onCreate();
} 公共无效setArrayListMapData(ArrayList的<&HashMap的LT;字符串,字符串>>使用setData)
{
ArrayList的使用setData =;
} 公众的ArrayList<&HashMap的LT;字符串,字符串>> getArrayListMapData()
{
返回数组列表;
}
}
登录:
01-03 14:13:14.509:E / AndroidRuntime(681):致命异常:主要
01-03 14:13:14.509:E / AndroidRuntime(681):了java.lang.RuntimeException:无法启动活动ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems}:了java.lang.RuntimeException:无法启动活动ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters}: java.lang.ClassCastException:android.app.Application
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.os.Handler.dispatchMessage(Handler.java:99)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.os.Looper.loop(Looper.java:123)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.ActivityThread.main(ActivityThread.java:4627)
01-03 14:13:14.509:E / AndroidRuntime(681):在java.lang.reflect.Method.invokeNative(本机方法)
01-03 14:13:14.509:E / AndroidRuntime(681):在java.lang.reflect.Method.invoke(Method.java:521)
01-03 14:13:14.509:E / AndroidRuntime(681):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
01-03 14:13:14.509:E / AndroidRuntime(681):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-03 14:13:14.509:E / AndroidRuntime(681):在dalvik.system.NativeStart.main(本机方法)
01-03 14:13:14.509:E / AndroidRuntime(681):了java.lang.RuntimeException:产生的原因无法启动活动ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters}: java.lang.ClassCastException:android.app.Application
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.widget.TabHost $ IntentContentStrategy.getContentView(TabHost.java:651)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.widget.TabHost.setCurrentTab(TabHost.java:323)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.widget.TabHost.addTab(TabHost.java:213)
01-03 14:13:14.509:E / AndroidRuntime(681):在com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems.onCreate(BreakfastLunchDinnerIndividualListOfItems.java:36)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-03 14:13:14.509:E / AndroidRuntime(681):11 ...更多
01-03 14:13:14.509:E / AndroidRuntime(681):java.lang.ClassCastException:产生的原因android.app.Application
01-03 14:13:14.509:E / AndroidRuntime(681):在com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters.onCreate(BLD_IndividualListOfItems_Starters.java:47)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-03 14:13:14.509:E / AndroidRuntime(681):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-03 14:13:14.509:E / AndroidRuntime(681):20 ...更多
移动属性
的android:NAME =com.android.app.MyApplication
到第一个应用
在清单元素并删除第二个应用
元素。
顺便说一句。是你的所有MyApplication
类确实在包 com.android.app </ code>?
编辑:你用不同的包,所以该行应
的android:NAME =com.example.multitabcheckboxselection.MyApplication
EDIT2 + 3:你已经把它作为一项活动了。除去活动,该属性必须进入应用
标记。
&LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.multitabcheckboxselection
安卓版code =1
机器人:=的versionName1.0&GT;&LT;用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =18/&GT;&LT;使用许可权的android:NAME =android.permission.INTERNET对/&GT;&lt;应用
机器人:名字=com.example.multitabcheckboxselection.MyApplication
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme&GT;
&LT;活动
机器人:名字=com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems
机器人:标签=@字符串/ APP_NAME&GT;
&所述;意图滤光器&gt;
&lt;作用机器人:名字=android.intent.action.MAIN/&GT; &LT;类机器人:名字=android.intent.category.LAUNCHER/&GT;
&所述; /意图滤光器&gt;
&LT; /活性GT;
&LT;活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters/&GT;
&LT;活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_MainCourse/&GT;
&LT;活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_SideCourse/&GT;
&LT;活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Others/&GT;
&LT;活动机器人:名字=com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Desert/&GT;
&LT;活动机器人:名字=com.example.multitabcheckboxselection.ResultActivity/&GT;
&LT; /用途&gt;&LT; /清单&GT;
What i am doing:: I am trying to use Myapplication class to send the data to next activity
Problem i am facing:: Having class cast exception
BLD_IndividualListOfItems_Starters.java
public class BLD_IndividualListOfItems_Starters extends Activity{
// Declare Variables
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
ListViewAdapterForAtomicListItemtype adapter;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
static String NAME = "rank";
Button btn;
String TYPE_FILTER;
StringBuilder result;
MyApplication mApplication;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mApplication = (MyApplication)getApplication();
// Get the view from listview_main.xml
setContentView(R.layout.listview_main);
TYPE_FILTER = getIntent().getExtras().getString("key_title");
Log.v("---- Value-Start---", TYPE_FILTER);
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listview);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
result = new StringBuilder();
for (int i = 0; i < arraylist.size(); i++) {
if (adapter.mysparse.get(i) == true) {
result.append(arraylist.get(i).get(BLD_IndividualListOfItems_Starters.NAME));
result.append("\n");
}
}
Intent n = new Intent(BLD_IndividualListOfItems_Starters.this, ResultActivity.class);
n.putExtra("buffer", result.toString());
startActivity(n);
}
});
// Execute DownloadJSON AsyncTask
new DownloadJSON().execute();
}
// DownloadJSON AsyncTask
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(BLD_IndividualListOfItems_Starters.this);
// Set progressdialog title
//mProgressDialog.setTitle("Fetching the information");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
String newurl = "?" + "Key=" + TYPE_FILTER;
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions.getJSONfromURL("http://54.218.73.244:7005/RestaurantAtomicListItemType/"+newurl);
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("restaurants");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
map.put(BLD_IndividualListOfItems_Starters.NAME, jsonobject.getString("MasterListMenuName"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapterForAtomicListItemtype(BLD_IndividualListOfItems_Starters.this, arraylist);
// Set the adapter to the ListView
mApplication.setArrayListMapData(arraylist);
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
}
ResultActivity.java
public class ResultActivity extends ListActivity {
ListView lstView;
ArrayList<HashMap<String,String>> arraylist = new ArrayList<HashMap<String,String>>();
String myName;
MyApplication mApplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
for(int i=0;i<10;i++)
{
HashMap<String,String> map = new HashMap<String,String>();
map.put("key", "value"+i);
arraylist.add(map);
}
String[] from = { "key" };
int[] to = { R.id.textView1 };
SimpleAdapter adapter= new SimpleAdapter(this, arraylist,R.layout.custom_single_list, from, to);
setListAdapter(adapter);
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.multitabcheckboxselection"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_MainCourse" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_SideCourse" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Others" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Desert" />
<activity android:name="com.example.multitabcheckboxselection.ResultActivity" />
</application>
<application
android:name="com.android.app.MyApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
</application>
</manifest>
ListViewAdapterForAtomicListItemtype.java
public class ListViewAdapterForAtomicListItemtype extends BaseAdapter implements OnCheckedChangeListener {
// Declare Variables
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
HashMap<String, String> resultp = new HashMap<String, String>();
SparseBooleanArray mysparse;
public ListViewAdapterForAtomicListItemtype(Context context,
ArrayList<HashMap<String, String>> arraylist) {
this.context = context;
data = arraylist;
mysparse = new SparseBooleanArray(data.size());
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView name;
CheckBox chk;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.listview_item_for_atomic_list_item_type, parent, false);
// Get the position
resultp = data.get(position);
// Locate the TextViews in listview_item.xml
name = (TextView) itemView.findViewById(R.id.textView_id_atomic_list_item_type);
chk = (CheckBox) itemView.findViewById(R.id.checkBox_atomic_list_item_type_id);
// Capture position and set results to the TextViews
name.setText(resultp.get(BLD_IndividualListOfItems_Starters.NAME));
chk.setTag(position);
chk.setChecked(mysparse.get(position, false));
chk.setOnCheckedChangeListener(this);
return itemView;
}
public boolean isChecked(int position) {
return mysparse.get(position, false);
}
public void setChecked(int position, boolean isChecked) {
mysparse.put(position, isChecked);
}
public void toggle(int position) {
setChecked(position, !isChecked(position));
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
mysparse.put((Integer) buttonView.getTag(), isChecked);
}
}
Log::
01-03 13:30:12.828: D/AndroidRuntime(461): Shutting down VM
01-03 13:30:12.828: W/dalvikvm(461): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-03 13:30:12.868: E/AndroidRuntime(461): FATAL EXCEPTION: main
01-03 13:30:12.868: E/AndroidRuntime(461): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters}: java.lang.ClassCastException: android.app.Application
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.os.Handler.dispatchMessage(Handler.java:99)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.os.Looper.loop(Looper.java:123)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-03 13:30:12.868: E/AndroidRuntime(461): at java.lang.reflect.Method.invokeNative(Native Method)
01-03 13:30:12.868: E/AndroidRuntime(461): at java.lang.reflect.Method.invoke(Method.java:521)
01-03 13:30:12.868: E/AndroidRuntime(461): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-03 13:30:12.868: E/AndroidRuntime(461): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-03 13:30:12.868: E/AndroidRuntime(461): at dalvik.system.NativeStart.main(Native Method)
01-03 13:30:12.868: E/AndroidRuntime(461): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters}: java.lang.ClassCastException: android.app.Application
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.widget.TabHost.addTab(TabHost.java:213)
01-03 13:30:12.868: E/AndroidRuntime(461): at com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems.onCreate(BreakfastLunchDinnerIndividualListOfItems.java:36)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-03 13:30:12.868: E/AndroidRuntime(461): ... 11 more
01-03 13:30:12.868: E/AndroidRuntime(461): Caused by: java.lang.ClassCastException: android.app.Application
01-03 13:30:12.868: E/AndroidRuntime(461): at com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters.onCreate(BLD_IndividualListOfItems_Starters.java:47)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-03 13:30:12.868: E/AndroidRuntime(461): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-03 13:30:12.868: E/AndroidRuntime(461): ... 20 more
01-03 13:30:15.563: I/Process(461): Sending signal. PID: 461 SIG: 9
{Edit}
BLD_IndividualListOfItems_Starters.java
public class BLD_IndividualListOfItems_Starters extends Activity{
// Declare Variables
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
ListViewAdapterForAtomicListItemtype adapter;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
static String NAME = "rank";
Button btn;
String TYPE_FILTER;
StringBuilder result;
MyApplication mApplication;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mApplication = (MyApplication)getApplicationContext();
// Get the view from listview_main.xml
setContentView(R.layout.listview_main);
TYPE_FILTER = getIntent().getExtras().getString("key_title");
Log.v("---- Value-Start---", TYPE_FILTER);
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listview);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
result = new StringBuilder();
for (int i = 0; i < arraylist.size(); i++) {
if (adapter.mysparse.get(i) == true) {
result.append(arraylist.get(i).get(BLD_IndividualListOfItems_Starters.NAME));
result.append("\n");
}
}
Intent n = new Intent(BLD_IndividualListOfItems_Starters.this, ResultActivity.class);
n.putExtra("buffer", result.toString());
startActivity(n);
}
});
// Execute DownloadJSON AsyncTask
new DownloadJSON().execute();
}
// DownloadJSON AsyncTask
private class DownloadJSON extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(BLD_IndividualListOfItems_Starters.this);
// Set progressdialog title
//mProgressDialog.setTitle("Fetching the information");
// Set progressdialog message
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create an array
arraylist = new ArrayList<HashMap<String, String>>();
String newurl = "?" + "Key=" + TYPE_FILTER;
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions.getJSONfromURL("http://54.218.73.244:7005/RestaurantAtomicListItemType/"+newurl);
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("restaurants");
for (int i = 0; i < jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
map.put(BLD_IndividualListOfItems_Starters.NAME, jsonobject.getString("MasterListMenuName"));
// Set the JSON Objects into the array
arraylist.add(map);
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void args) {
// Pass the results into ListViewAdapter.java
adapter = new ListViewAdapterForAtomicListItemtype(BLD_IndividualListOfItems_Starters.this, arraylist);
// Set the adapter to the ListView
mApplication.setArrayListMapData(arraylist);
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
}
MyApplication.java
package com.example.multitabcheckboxselection;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Application;
public class MyApplication extends Application {
ArrayList<HashMap<String, String>> arraylist;
@Override
public void onCreate() {
super.onCreate();
}
public void setArrayListMapData(ArrayList<HashMap<String, String>> setData)
{
arraylist = setData;
}
public ArrayList<HashMap<String, String>> getArrayListMapData()
{
return arraylist;
}
}
{Edit-3}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.multitabcheckboxselection"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_MainCourse" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_SideCourse" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Others" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Desert" />
<activity android:name="com.example.multitabcheckboxselection.ResultActivity" />
</application>
<application
android:allowBackup="true"
android:name="com.example.multitabcheckboxselection.MyApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
</application>
</manifest>
MyApplication.java
package com.example.multitabcheckboxselection;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Application;
public class MyApplication extends Application {
ArrayList<HashMap<String, String>> arraylist;
@Override
public void onCreate() {
super.onCreate();
}
public void setArrayListMapData(ArrayList<HashMap<String, String>> setData)
{
arraylist = setData;
}
public ArrayList<HashMap<String, String>> getArrayListMapData()
{
return arraylist;
}
}
Log::
01-03 14:13:14.509: E/AndroidRuntime(681): FATAL EXCEPTION: main
01-03 14:13:14.509: E/AndroidRuntime(681): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters}: java.lang.ClassCastException: android.app.Application
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.os.Handler.dispatchMessage(Handler.java:99)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.os.Looper.loop(Looper.java:123)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-03 14:13:14.509: E/AndroidRuntime(681): at java.lang.reflect.Method.invokeNative(Native Method)
01-03 14:13:14.509: E/AndroidRuntime(681): at java.lang.reflect.Method.invoke(Method.java:521)
01-03 14:13:14.509: E/AndroidRuntime(681): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-03 14:13:14.509: E/AndroidRuntime(681): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-03 14:13:14.509: E/AndroidRuntime(681): at dalvik.system.NativeStart.main(Native Method)
01-03 14:13:14.509: E/AndroidRuntime(681): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.multitabcheckboxselection/com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters}: java.lang.ClassCastException: android.app.Application
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.widget.TabHost.addTab(TabHost.java:213)
01-03 14:13:14.509: E/AndroidRuntime(681): at com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems.onCreate(BreakfastLunchDinnerIndividualListOfItems.java:36)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-03 14:13:14.509: E/AndroidRuntime(681): ... 11 more
01-03 14:13:14.509: E/AndroidRuntime(681): Caused by: java.lang.ClassCastException: android.app.Application
01-03 14:13:14.509: E/AndroidRuntime(681): at com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters.onCreate(BLD_IndividualListOfItems_Starters.java:47)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-03 14:13:14.509: E/AndroidRuntime(681): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-03 14:13:14.509: E/AndroidRuntime(681): ... 20 more
Move the attribute
android:name="com.android.app.MyApplication"
to the first application
element in the manifest and delete the second application
element.
Btw. is your MyApplication
class really in the package com.android.app
?
EDIT: you use a different package, so the line should be
android:name="com.example.multitabcheckboxselection.MyApplication"
EDIT2+3: you have put it as an activity now. remove the activity, the attribute must go into the application
tag.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.multitabcheckboxselection"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="com.example.multitabcheckboxselection.MyApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.multitabcheckboxselection.BreakfastLunchDinnerIndividualListOfItems"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Starters" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_MainCourse" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_SideCourse" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Others" />
<activity android:name="com.example.multitabcheckboxselection.BLD_IndividualListOfItems_Desert" />
<activity android:name="com.example.multitabcheckboxselection.ResultActivity" />
</application>
</manifest>
这篇关于android系统中有一个例外classcast同时使用所有MyApplication类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!