我正在尝试用textvIEw填充单个ListvIEw,但是在第60行出现以下错误,即
ListVIEw.setAdapter(adapter);
这是我完整的日志.
04-16 10:51:38.953: E/AndroIDRuntime(3068): FATAL EXCEPTION: main04-16 10:51:38.953: E/AndroIDRuntime(3068): java.lang.RuntimeException: Unable to start activity ComponentInfo{}: java.lang.NullPointerException04-16 10:51:38.953: E/AndroIDRuntime(3068): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)04-16 10:51:38.953: E/AndroIDRuntime(3068): at androID.app.ActivityThread.access00(ActivityThread.java:117)04-16 10:51:38.953: E/AndroIDRuntime(3068): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:935)04-16 10:51:38.953: E/AndroIDRuntime(3068): at androID.os.Handler.dispatchMessage(Handler.java:99)04-16 10:51:38.953: E/AndroIDRuntime(3068): at androID.os.Looper.loop(Looper.java:130)04-16 10:51:38.953: E/AndroIDRuntime(3068): at androID.app.ActivityThread.main(ActivityThread.java:3687)04-16 10:51:38.953: E/AndroIDRuntime(3068): at java.lang.reflect.Method.invokeNative(Native Method)04-16 10:51:38.953: E/AndroIDRuntime(3068): at java.lang.reflect.Method.invoke(Method.java:507)04-16 10:51:38.953: E/AndroIDRuntime(3068): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)04-16 10:51:38.953: E/AndroIDRuntime(3068): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:600)04-16 10:51:38.953: E/AndroIDRuntime(3068): at dalvik.system.NativeStart.main(Native Method)04-16 10:51:38.953: E/AndroIDRuntime(3068): Caused by: java.lang.NullPointerException04-16 10:51:38.953: E/AndroIDRuntime(3068): at s..onCreate(Urgence.java:60)04-16 10:51:38.953: E/AndroIDRuntime(3068): at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)04-16 10:51:38.953: E/AndroIDRuntime(3068): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1615)04-16 10:51:38.953: E/AndroIDRuntime(3068): ... 11 more
这是我的清单课程
public class ListClass extends Activity { // Array of strings storing country names String[] countrIEs = new String[] { "Services opposition", "Service Carte bancaire a l'etranger" }; // Array of integers points to images stored in /res/drawable-ldpi/ int[] flags = new int[]{ R.drawable.arrow, R.drawable.arrow }; /** Called when the activity is first created. */ @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.urgence); // Each row in the List stores country name, currency and flag List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>(); for(int i=0;i<2;i++){ HashMap<String, String> hm = new HashMap<String,String>(); hm.put("txt", countrIEs[i]); hm.put("flag", Integer.toString(flags[i]) ); aList.add(hm); } // Keys used in Hashmap String[] from = { "txt","flag"}; // IDs of vIEws in ListvIEw_layout int[] to = { R.ID.single_text,R.ID.single_image}; // Instantiating an adapter to store each items // R.layout.ListvIEw_layout defines the layout of each item SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.ListvIEw_layout, from, to); // Getting a reference to ListvIEw of main.xml layout file ListVIEw ListVIEw = ( ListVIEw ) findVIEwByID(R.ID.List); // Setting the adapter to the ListVIEw ListVIEw.setAdapter(adapter); }}
谁知道为什么我的适配器为空
更新:
这是我的xml文件中的列表视图
<ListVIEw androID:ID="@androID:ID/List" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"/>
解决方法:
当活动xml中的ID与java类中引用的ID不同时,会看到此错误.
更改以下行
androID:ID="@androID:ID/List"
至
androID:ID="@+ID/List"
在您的XML文件中.
总结以上是内存溢出为你收集整理的android-无法启动活动ComponentInfo…NullPointerException全部内容,希望文章能够帮你解决android-无法启动活动ComponentInfo…NullPointerException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)