本文介绍了未能填写的Android使用Java微调值从Bean类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
公共类BriefFragmentActivity扩展片段
{
公共BriefFragmentActivity()
{
}
公共静态最后弦乐ARG_SECTION_NUMBER =SECTION_NUMBER;
字符串getParameter_Url =参数/ getParameters
微调spinnerSystemType;
ArrayList的<串GT; systemTypeArrayList;
DataBaseAdapter dataBaseAdapterInstance;
@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
捆绑savedInstanceState){
视图V = inflater.inflate(R.layout.brief_fragment_view,NULL);
getAllSpinnerValues();
spinnerSystemType =(微调)v.findViewById(R.id.spinner_systemtype);
返回伏;
} 私人无效getAllSpinnerValues()
{
systemTypeArrayList =新的ArrayList<串GT;();
dataBaseAdapterInstance =新DataBaseAdapter(getActivity()getApplicationContext());
dataBaseAdapterInstance.openToRead();
清单<参数> PARAMETERLIST =新的ArrayList<参数>();
PARAMETERLIST = dataBaseAdapterInstance.getParameterList();
对于(参数p:PARAMETERLIST)
{
Log.i(参数列表,+ p.getId()+现金code+ p.getCash code()+.....+ p.getParamType()) ;
如果(p.getParamType()。修剪()。的toString()。equalsIgnoreCase(系统类型))
{
Log.i(系统类型,字符串比较块);
systemTypeArrayList.add(p.getParamDescription()修剪()的toString());
Log.i(systemTypeArrayList:,+ systemTypeArrayList); ** //从bean类获得该线路上正确的数据..... **
// **错误是试图添加此ArrayList到ArrayAdapter时**
ArrayAdapter<串GT; adapterSystemType =新ArrayAdapter<串GT;(getActivity(),R.layout.custom_spinner,systemTypeArrayList);adapterSystemType.setDropDownViewResource(R.layout.custom_spinner_item_list);
spinnerSystemType.setAdapter(adapterSystemType);
adapterSystemType.notifyDataSetChanged();}
其他
{
Log.i(价值观,+ p.getParamType());
}
}
dataBaseAdapterInstance.close();
}
}
请忽略的错误{}
我认为有上下文所以它给我error.Error从这个LOC开始的一些错误:
ArrayAdapter adapterSystemType =新ArrayAdapter(getActivity(),R.layout.custom_spinner,systemTypeArrayList);
这之前的一切工作正常。
这里是logcat的:
4月12日至20日:48:26.115:E / AndroidRuntime(20657):致命异常:主要
四月12日至20日:48:26.115:E / AndroidRuntime(20657):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.survey.management.activity / com.survey.management.activity.FragmentMainActivity}:显示java.lang.NullPointerException
四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.app.ActivityThread.access $ 600(ActivityThread.java:140)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1227)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.os.Handler.dispatchMessage(Handler.java:99)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.os.Looper.loop(Looper.java:137)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.app.ActivityThread.main(ActivityThread.java:4898)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在java.lang.reflect.Method.invokeNative(本机方法)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在java.lang.reflect.Method.invoke(Method.java:511)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1006)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在dalvik.system.NativeStart.main(本机方法)四月12日至20日:48:26.115:E / AndroidRuntime(20657):致:显示java.lang.NullPointerException四月12日至20日:48:26.115:E / AndroidRuntime(20657):在com.survey.management.activity.BriefFragmentActivity.getAllSpinnerValues(BriefFragmentActivity.java:701)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在com.survey.management.activity.BriefFragmentActivity.onCreateView(BriefFragmentActivity.java:67)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1167)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.app.Activity.performStart(Activity.java:5216)四月12日至20日:48:26.115:E / AndroidRuntime(20657):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2073)四月12日至20日:48:26.115:E / AndroidRuntime(20657):... 11个
解决方案
使用
dataBaseAdapterInstance =新DataBaseAdapter(getActivity());
还有 spinnerSystemType
未初始化
视图V = inflater.inflate(R.layout.brief_fragment_view,NULL);
spinnerSystemType =(微调)v.findViewById(R.id.spinner1);
//确保ID spinner1是正确的
public class BriefFragmentActivity extends Fragment
{
public BriefFragmentActivity()
{
}
public static final String ARG_SECTION_NUMBER = "section_number";
String getParameter_Url = "parameters/getParameters";
Spinner spinnerSystemType;
ArrayList<String> systemTypeArrayList;
DataBaseAdapter dataBaseAdapterInstance;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.brief_fragment_view, null);
getAllSpinnerValues();
spinnerSystemType = (Spinner) v.findViewById(R.id.spinner_systemtype);
return v;
}
private void getAllSpinnerValues()
{
systemTypeArrayList = new ArrayList<String>();
dataBaseAdapterInstance = new DataBaseAdapter(getActivity().getApplicationContext());
dataBaseAdapterInstance.openToRead();
List<Parameters> parameterList = new ArrayList<Parameters>();
parameterList = dataBaseAdapterInstance.getParameterList();
for (Parameters p : parameterList)
{
Log.i("parameter list",""+p.getId() + "cash code" + p.getCashCode() +"....." + p.getParamType());
if(p.getParamType().trim().toString().equalsIgnoreCase("system type"))
{
Log.i("system type","string comparison block");
systemTypeArrayList.add(p.getParamDescription().trim().toString());
Log.i("systemTypeArrayList:",""+systemTypeArrayList); **// getting correct data on this line from bean class.....**
//**Error is when trying to add this arrayList to ArrayAdapter**
ArrayAdapter<String> adapterSystemType = new ArrayAdapter<String>(getActivity(),R.layout.custom_spinner,systemTypeArrayList);
adapterSystemType.setDropDownViewResource(R.layout.custom_spinner_item_list);
spinnerSystemType.setAdapter(adapterSystemType);
adapterSystemType.notifyDataSetChanged();
}
else
{
Log.i("values",""+p.getParamType());
}
}
dataBaseAdapterInstance.close();
}
}
please ignore mistake of { } i think there is some mistake of Context thats why its giving me error.Error starts from this LOC:
ArrayAdapter adapterSystemType = new ArrayAdapter(getActivity(),R.layout.custom_spinner,systemTypeArrayList); before this everything working fine.Here is the Logcat:
12-20 04:48:26.115: E/AndroidRuntime(20657): FATAL EXCEPTION: main
12-20 04:48:26.115: E/AndroidRuntime(20657): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.survey.management.activity/com.survey.management.activity.FragmentMainActivity}: java.lang.NullPointerException
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.app.ActivityThread.access$600(ActivityThread.java:140)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.os.Looper.loop(Looper.java:137)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.app.ActivityThread.main(ActivityThread.java:4898)
12-20 04:48:26.115: E/AndroidRuntime(20657): at java.lang.reflect.Method.invokeNative(Native Method)
12-20 04:48:26.115: E/AndroidRuntime(20657): at java.lang.reflect.Method.invoke(Method.java:511)
12-20 04:48:26.115: E/AndroidRuntime(20657): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-20 04:48:26.115: E/AndroidRuntime(20657): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-20 04:48:26.115: E/AndroidRuntime(20657): at dalvik.system.NativeStart.main(Native Method)
12-20 04:48:26.115: E/AndroidRuntime(20657): Caused by: java.lang.NullPointerException
12-20 04:48:26.115: E/AndroidRuntime(20657): at com.survey.management.activity.BriefFragmentActivity.getAllSpinnerValues(BriefFragmentActivity.java:701)
12-20 04:48:26.115: E/AndroidRuntime(20657): at com.survey.management.activity.BriefFragmentActivity.onCreateView(BriefFragmentActivity.java:67)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1167)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.app.Activity.performStart(Activity.java:5216)
12-20 04:48:26.115: E/AndroidRuntime(20657): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2073)
12-20 04:48:26.115: E/AndroidRuntime(20657): ... 11 more
解决方案
Use
dataBaseAdapterInstance = new DataBaseAdapter(getActivity());
Also spinnerSystemType
is not initialized
View v = inflater.inflate(R.layout.brief_fragment_view, null);
spinnerSystemType =(Spinner)v.findViewById(R.id.spinner1);
// make sure the id spinner1 is right
这篇关于未能填写的Android使用Java微调值从Bean类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!