android空指针异常,求大神指教,已纠结好几天了。。。

package com.rong.shop.myshop.home;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;

import com.rong.shop.R;

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

/**

  • Created by Administrator on 2016/8/13.
    */
    public class MyFragment_home extends Fragment {

    //ViewPager
    private ViewPager vpager_one;
    private ArrayList aList;
    private Adapter_homeViewPager mAdapter;

    //GridView
    private GridView gridview;
    private ImageView imageview;
    private Context mcontext = this.getActivity();
    private List> listitem;
    private SimpleAdapter gAdapter;
    private int[] imgIds;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fg_home, container, false);

    //ViewPager
    vpager_one = (ViewPager) view.findViewById(R.id.vpager);
    
    aList = new ArrayList<View>();
    LayoutInflater li = getLayoutInflater(null);
    aList.add(li.inflate(R.layout.fg_home_viewpager_view_1, null, false));
    aList.add(li.inflate(R.layout.fg_home_viewpager_view_2, null, false));
    aList.add(li.inflate(R.layout.fg_home_viewpager_view_3, null, false));
    aList.add(li.inflate(R.layout.fg_home_viewpager_view_4, null, false));
    aList.add(li.inflate(R.layout.fg_home_viewpager_view_5, null, false));
    
    mAdapter = new Adapter_homeViewPager(aList);
    vpager_one.setAdapter(mAdapter);
    
    //GridView
    gridview = (GridView)view.findViewById(R.id.gridview);
    
    listitem= new ArrayList<>();
    imgIds = new int[]{
            R.drawable.fg_home_gridview_1, R.drawable.fg_home_gridview_2,
            R.drawable.fg_home_gridview_3, R.drawable.fg_home_gridview_4,
            R.drawable.fg_home_gridview_5, R.drawable.fg_home_gridview_6,
            R.drawable.fg_home_gridview_7, R.drawable.fg_home_gridview_8,
    };
    for (int i = 0; i < imgIds.length; i++) {
        Map<String, Object> showitem = new HashMap<String, Object>();这里是第七十行报错的代码
        showitem.put("image", imgIds[i]);
        listitem.add(showitem);
    }
    
    gAdapter = new SimpleAdapter(mcontext, listitem, R.layout.fg_home_gridview_item,
            new String[] { "image" }, new int[]{R.id.gridview_image});
    gridview.setAdapter(gAdapter);
    
    return view;
    

    }
    }

报错信息是
Caused by: java.lang.NullPointerException

at com.rong.shop.myshop.home.MyFragment_home.onCreateView(MyFragment_home.java:70)

3个回答

最好把你的日志全部忒出来,Map itemMap = new HashMap();这句是没有语法错误的

08-31 07:27:27.476 681-1062/? A/ProcessStats: Starting service ServiceState{427bfa08 com.android.mms.transaction.SmsReportService pkg=com.android.mms proc=427bfa08} without owner
08-31 07:27:27.506 681-1062/? A/ProcessStats: Starting service ServiceState{42671db8 com.miui.cloudservice.state.MiCloudSyncStateService pkg=com.miui.cloudservice proc=42671db8} without owner
08-31 07:27:27.526 681-1062/? A/ProcessStats: Starting service ServiceState{41fb6b48 com.miui.analytics.internal.WakeupService pkg=com.miui.analytics proc=41fb6b48} without owner
08-31 07:27:27.536 681-1062/? A/ProcessStats: Starting service ServiceState{41feb5a8 com.android.thememanager.service.ThemeTaskService pkg=com.android.thememanager proc=41feb5a8} without owner
08-31 07:27:27.837 23788-23788/? E/ActivityThread: Failed to find provider info for com.tencent.mm.coolassist.debugprovider
08-31 07:27:31.150 681-699/? A/ProcessStats: Starting service ServiceState{427bfa08 com.android.mms.transaction.SmsReportService pkg=com.android.mms proc=427bfa08} without owner
08-31 07:27:31.270 681-699/? A/ProcessStats: Starting service ServiceState{42671db8 com.miui.cloudservice.state.MiCloudSyncStateService pkg=com.miui.cloudservice proc=42671db8} without owner
08-31 07:27:31.340 681-699/? A/ProcessStats: Starting service ServiceState{41fb6b48 com.miui.analytics.internal.WakeupService pkg=com.miui.analytics proc=41fb6b48} without owner
08-31 07:27:31.360 681-699/? A/ProcessStats: Starting service ServiceState{41feb5a8 com.android.thememanager.service.ThemeTaskService pkg=com.android.thememanager proc=41feb5a8} without owner
08-31 07:27:32.631 824-824/? E/ActivityThread: Failed to find provider info for com.xiaomi.tv.gallerylockscreen.lockscreen_magazine_provider
08-31 07:27:52.271 24361-24386/? E/ActivityThread: Failed to find provider info for telocation
08-31 07:27:52.271 24361-24386/? E/ActivityThread: Failed to find provider info for telocation
08-31 07:27:56.445 681-1233/? A/ProcessStats: Starting service ServiceState{4224b898 com.morgoo.droidplugin.stub.ServiceStub$StubP01$P00 pkg=com.qihoo.appstore proc=4224b898} without owner
08-31 07:27:56.465 681-1233/? A/ProcessStats: Starting service ServiceState{41feb5a8 com.android.thememanager.service.ThemeTaskService pkg=com.android.thememanager proc=41feb5a8} without owner
08-31 07:27:56.885 681-1043/system_process A/ProcessStats: Starting service ServiceState{4224b898 com.morgoo.droidplugin.stub.ServiceStub$StubP01$P00 pkg=com.qihoo.appstore proc=4224b898} without owner
08-31 07:27:56.895 681-1043/system_process A/ProcessStats: Starting service ServiceState{41feb5a8 com.android.thememanager.service.ThemeTaskService pkg=com.android.thememanager proc=41feb5a8} without owner
08-31 07:28:01.343 681-1227/system_process A/ProcessStats: Starting service ServiceState{4224b898 com.morgoo.droidplugin.stub.ServiceStub$StubP01$P00 pkg=com.qihoo.appstore proc=4224b898} without owner
08-31 07:28:01.383 681-1227/system_process A/ProcessStats: Starting service ServiceState{41feb5a8 com.android.thememanager.service.ThemeTaskService pkg=com.android.thememanager proc=41feb5a8} without owner
08-31 07:37:31.857 25695-25695/com.tencent.mm:tools E/ActivityThread: Failed to find provider info for com.tencent.mm.coolassist.debugprovider
08-31 07:38:42.275 824-824/? E/ActivityThread: Failed to find provider info for com.xiaomi.tv.gallerylockscreen.lockscreen_magazine_provider
08-31 07:39:24.426 824-824/? E/ActivityThread: Failed to find provider info for com.xiaomi.tv.gallerylockscreen.lockscreen_magazine_provider
08-31 07:54:54.325 824-824/? E/ActivityThread: Failed to find provider info for com.xiaomi.tv.gallerylockscreen.lockscreen_magazine_provider
08-31 08:10:55.583 28881-28881/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rong.shop, PID: 28881
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rong.shop/com.rong.shop.myshop.home.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2212)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.widget.SimpleAdapter.(SimpleAdapter.java:85)
at com.rong.shop.myshop.home.MyFragment_home.onCreateView(MyFragment_home.java:70)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1671)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:619)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5241)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271) 
at android.app.ActivityThread.access$800(ActivityThread.java:144) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5146) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566) 
at dalvik.system.NativeStart.main(Native Method) 
08-31 08:13:02.737 29104-29154/com.android.contacts E/ActivityThread: Failed to find provider info for miui.yellowpage
08-31 08:13:02.947 1166-29164/android.process.acore E/ActivityThread: Failed to find provider info for miui.yellowpage
08-31 08:13:03.447 29104-29104/com.android.contacts E/ActivityThread: Failed to find provider info for telocation
08-31 08:13:03.447 29104-29104/com.android.contacts E/ActivityThread: Failed to find provider info for telocation
08-31 08:13:03.487 1166-29191/android.process.acore E/ActivityThread: Failed to find provider info for miui.yellowpage
08-31 08:13:09.393 29241-29241/com.android.incallui E/ActivityThread: Failed to find provider info for telocation
08-31 08:13:09.393 29241-29241/com.android.incallui E/ActivityThread: Failed to find provider info for telocation
08-31 08:13:10.084 29241-29276/com.android.incallui E/RenderScript: Successfully loaded runtime: libRSDriver_adreno.so
08-31 08:13:21.125 220-1100/? E/ACDB-LOADER: Error: ACDB EC_REF_RX returned = -8
08-31 08:13:21.135 220-220/? E/ACDB-LOADER: Error: ACDB EC_REF_RX returned = -8
08-31 08:13:21.195 1007-1007/com.android.phone E/BluetoothPhoneService: Could not get a handle on Connection object for the call
08-31 08:13:24.388 220-1100/? E/ACDB-LOADER: Error: ACDB EC_REF_RX returned = -8
08-31 08:13:24.508 220-713/? E/ACDB-LOADER: Error: Remote ACDB ID lookup failed = -8
08-31 08:13:24.538 220-713/? E/ACDB-LOADER: Error: Remote ACDB ID lookup failed = -8

                                        [ 08-31 08:13:24.568   220:  713 D/         ]
                                        csd_disable_devices: devices disabled rx=7, tx=65, ec=43

08-31 08:13:24.788 1007-1007/com.android.phone E/BluetoothPhoneService: Could not get a handle on Connection object for the call
08-31 08:13:24.798 1007-1007/com.android.phone E/BluetoothPhoneService: Could not get a handle on Connection object for the call
08-31 08:13:29.873 29104-29104/com.android.contacts E/VOIPUtil: miui voip not installed
08-31 08:13:29.893 29104-29104/com.android.contacts E/VOIPUtil: miui voip not installed
08-31 08:13:29.933 1166-29377/android.process.acore E/ActivityThread: Failed to find provider info for miui.yellowpage
08-31 08:13:29.943 29104-29104/com.android.contacts E/VOIPUtil: miui voip not installed
08-31 08:13:29.953 29104-29190/com.android.contacts E/VOIPUtil: miui voip not installed
08-31 08:13:30.194 1166-29382/android.process.acore E/ActivityThread: Failed to find provider info for miui.yellowpage
08-31 08:13:32.075 220-1101/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:13:32.075 220-1101/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:13:32.075 220-1101/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:13:32.075 220-1101/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:13:32.185 220-1101/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:13:32.185 220-1101/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:13:32.185 220-1101/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:13:32.185 220-1101/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:13:32.185 220-709/? E/ACDB-LOADER: Error: ACDB EC_REF_RX returned = -8
08-31 08:13:32.216 220-709/? E/ACDB-LOADER: Error: ACDB AudProc vol returned = -8
08-31 08:13:32.366 220-709/? E/ACDB-LOADER: Error: Remote ACDB ID lookup failed = -8

                                        [ 08-31 08:13:32.366   220:  709 D/         ]
                                        enable_device: Remote rx 7, tx 65


                                        [ 08-31 08:13:32.366   220:  709 D/         ]
                                        get_sample_rate: Rate 48000


                                        [ 08-31 08:13:32.366   220:  709 D/         ]
                                        get_sample_rate: Rate 48000


                                        [ 08-31 08:13:32.466   220:  709 D/         ]
                                        enable_device: dev_id1=7 dev_id=65 successfull

08-31 08:13:32.466 220-709/? E/ACDB-LOADER: Error: Remote ACDB ID lookup failed = -8
08-31 08:13:32.486 220-709/? E/ACDB-LOADER: Error: Remote ACDB ID lookup failed = -8

                                        [ 08-31 08:13:32.486   220:  709 D/         ]
                                        get_sample_rate: Rate 48000


                                        [ 08-31 08:13:32.486   220:  709 D/         ]
                                        get_sample_rate: Rate 48000

08-31 08:13:32.716 220-711/? E/ACDB-LOADER: Error: ACDB EC_REF_RX returned = -8
08-31 08:13:32.846 1007-1007/com.android.phone E/BluetoothPhoneService: Could not get a handle on Connection object for the call
08-31 08:13:32.856 1007-1007/com.android.phone E/BluetoothPhoneService: Could not get a handle on Connection object for the call
08-31 08:13:32.886 1007-1007/com.android.phone E/BluetoothPhoneService: Could not get a handle on Connection object for the call
08-31 08:13:45.118 220-1101/? E/ACDB-LOADER: Error: ACDB EC_REF_RX returned = -8
08-31 08:13:45.118 220-1100/? E/ACDB-LOADER: Error: ACDB EC_REF_RX returned = -8
08-31 08:13:45.168 1007-1007/com.android.phone E/BluetoothPhoneService: Could not get a handle on Connection object for the call
08-31 08:14:29.642 220-1100/? E/ACDB-LOADER: Error: ACDB EC_REF_RX returned = -8
08-31 08:14:29.742 220-1101/? E/ACDB-LOADER: Error: Remote ACDB ID lookup failed = -8
08-31 08:14:29.762 220-1101/? E/ACDB-LOADER: Error: Remote ACDB ID lookup failed = -8

                                         [ 08-31 08:14:29.792   220: 1101 D/         ]
                                         csd_disable_devices: devices disabled rx=7, tx=65, ec=43

08-31 08:14:29.932 1007-1007/com.android.phone E/BluetoothPhoneService: Could not get a handle on Connection object for the call
08-31 08:14:29.942 1007-1007/com.android.phone E/BluetoothPhoneService: Could not get a handle on Connection object for the call
08-31 08:14:30.172 29104-29104/com.android.contacts E/VOIPUtil: miui voip not installed
08-31 08:14:30.172 29104-29104/com.android.contacts E/VOIPUtil: miui voip not installed
08-31 08:14:30.182 29104-29167/com.android.contacts E/VOIPUtil: miui voip not installed
08-31 08:14:30.192 1166-29519/android.process.acore E/ActivityThread: Failed to find provider info for miui.yellowpage
08-31 08:14:30.202 29104-29104/com.android.contacts E/VOIPUtil: miui voip not installed
08-31 08:14:30.462 1166-29523/android.process.acore E/ActivityThread: Failed to find provider info for miui.yellowpage
08-31 08:14:33.495 824-824/com.android.systemui E/ActivityThread: Failed to find provider info for com.xiaomi.tv.gallerylockscreen.lockscreen_magazine_provider
08-31 08:14:33.836 681-693/system_process E/MediaFocusControl: Error updating focussed RCC to RCD
java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:57)
at android.media.MediaFocusControl.registerRemoteControlDisplay_int(MediaFocusControl.java:2182)
at android.media.MediaFocusControl.registerRemoteController(MediaFocusControl.java:217)
at android.media.AudioService.registerRemoteController(AudioService.java:4538)
at android.media.IAudioService$Stub.onTransact(IAudioService.java:614)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
08-31 08:15:06.841 681-694/system_process E/qcom_sensors_hal: hal_process_time_resp: Resetting rollover count from 0 to 0
08-31 08:15:06.911 220-29642/? E/AwesomePlayer: LPAPlayer::Clip duration setting of less than 30sec not supported, defaulting to 60sec
08-31 08:15:06.991 220-29647/? E/AwesomePlayer: LPAPlayer::Clip duration setting of less than 30sec not supported, defaulting to 60sec
08-31 08:15:06.991 220-220/? E/AwesomePlayer: LPAPlayer::Clip duration setting of less than 30sec not supported, defaulting to 60sec
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.001 220-220/? E/AudioPolicyManagerALSA: unknown stream type
08-31 08:15:07.451 824-824/com.android.systemui E/MediaPlayer: Should have subtitle controller already set
08-31 08:15:17.721 681-694/system_process E/qcom_sensors_hal: hal_process_time_resp: Resetting rollover count from 0 to 0

楼主解决这个问题了吗?我也遇到了相同的问题

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问