为了账号安全,请及时绑定邮箱和手机立即绑定

无法运行,请问哪里出错了?

package com.ash.gridview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

   private GridView gridView;
   private List<Map<String, Object>> dataList;
   private int[] icon = {R.drawable.on2, R.drawable.on2, R.drawable.on2
           , R.drawable.on2, R.drawable.on2, R.drawable.on2, R.drawable.on2, R.drawable.on2,};
   private String[] iconName = {"1", "2", "3", "4", "5", "6", "7", "8"};
   private SimpleAdapter adapter;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       // setContentView(R.layout.activity_main);
       setContentView(R.layout.main);
       getData();
       gridView = (GridView) findViewById(R.id.gridview);
       
       dataList = new ArrayList<Map<String, Object>>();
       adapter = new SimpleAdapter(this, getData(), R.layout.tem, new String[]{"image", "text"}
               , new int[]{R.id.image, R.id.text});
       gridView.setAdapter(adapter);
   }

   private List<Map<String, Object>> getData() {
       Map<String, Object> map = new HashMap<String, Object>();
       for (int i = 0; i < icon.length; i++) {
           map.put("image", icon[i]);
           map.put("text", iconName[i]);
           dataList.add(map);
       }

       return dataList;

   }
}


build.gradle

defaultConfig {
    applicationId "com.ash.gridview"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

运行手机 API 16 ,请问哪里出问题了?

正在回答

5 回答

代码31行  你看看你xml文件是tem还是item  (R.layout.tem)

0 回复 有任何疑惑可以回复我~
#1

ASH975 提问者

非常感谢!
2016-06-28 回复 有任何疑惑可以回复我~
04-10 13:06:04.645 26654-26654/com.ash.gridview E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ash.gridview/com.ash.gridview.MainActivity}: java.lang.NullPointerException
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
                                                                      at android.app.ActivityThread.access$600(ActivityThread.java:138)
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                      at android.os.Looper.loop(Looper.java:213)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:4787)
                                                                      at java.lang.reflect.Method.invokeNative(Native Method)
                                                                      at java.lang.reflect.Method.invoke(Method.java:511)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
                                                                      at dalvik.system.NativeStart.main(Native Method)
                                                                   Caused by: java.lang.NullPointerException
                                                                      at com.ash.gridview.MainActivity.getData(MainActivity.java:52)
                                                                      at com.ash.gridview.MainActivity.onCreate(MainActivity.java:33)
                                                                      at android.app.Activity.performCreate(Activity.java:5008)
                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096) 
                                                                      at android.app.ActivityThread.access$600(ActivityThread.java:138) 
                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207) 
                                                                      at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                      at android.os.Looper.loop(Looper.java:213) 
                                                                      at android.app.ActivityThread.main(ActivityThread.java:4787) 
                                                                      at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                      at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 
                                                                      at dalvik.system.NativeStart.main(Native Method)


0 回复 有任何疑惑可以回复我~
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2321Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72321Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2321Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72321Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42321Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2321Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:buildInfoDebugLoader
:app:transformClassesWithExtractJarsForDebug UP-TO-DATE
:app:transformClassesWithInstantRunVerifierForDebug UP-TO-DATE
:app:transformClassesWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:transformResourcesAndNative_libsWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:transformClassesWithInstantRunForDebug UP-TO-DATE
:app:transformClasses_enhancedWithInstant+reloadDexForDebug UP-TO-DATE
:app:incrementalDebugTasks
:app:prePackageMarkerForDebug
:app:fastDeployDebugExtractor UP-TO-DATE
:app:generateDebugInstantRunAppInfo UP-TO-DATE
:app:transformClassesWithDexForDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug UP-TO-DATE
:app:zipalignDebug UP-TO-DATE
:app:fullDebugBuildInfoGenerator
:app:assembleDebug
Information:BUILD SUCCESSFUL
Information:Total time: 0.707 secs
Information:0 errors
Information:0 warnings
Information:See complete output in console
0 回复 有任何疑惑可以回复我~

是空指针了,还是内存溢出了

0 回复 有任何疑惑可以回复我~
#1

ASH975 提问者

不好意思,好像并没有发现错误..
2016-04-08 回复 有任何疑惑可以回复我~

兄弟,你得把你的错误代码贴上来才行啊

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android攻城狮的第二门课(第1季)
  • 参与学习       111172    人
  • 解答问题       1457    个

本课程由浅入深地带您学会Android的常用控件的开发和使用

进入课程

无法运行,请问哪里出错了?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信