android - java.lang.RuntimeException : Unable to start activity ComponentInfo 错误

标签 android nullpointerexception runtimeexception

我已经检查了堆栈上的大多数解决方案以解决此错误,但不幸的是无法解决我的问题。以下是我遇到此错误的代码

public class ImageGrid extends BaseActivity {
    private GridView grid;
      private MyAdapter mAdapter;
      private DBAdapter mdbAdapter;
      private DisplayImageOptions options;
      DBAdapter localDBAdapter;
      Button play;
      String str, strid;
      String delay;
      TextView tv1;
      private Uri media;
      Cursor localCursor2, imageCursor;
      ArrayList<String> localArrayList, imageArray;
      private RadioGroup effects;
      private RadioGroup more;
      private RadioButton effectsbtn;
      private RadioButton morebtn;
      private int effectNo;
      DraggableGridView images;
      private FullImageLoader mLoder ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_grid);
        this.strid = getIntent().getStringExtra("boardid");
        this.media=getIntent().getData();
        this.mdbAdapter = new DBAdapter(getBaseContext());
        this.options = new DisplayImageOptions.Builder().showStubImage(R.drawable.ic_gallery).showImageForEmptyUri(R.drawable.ic_gallery).cacheInMemory().cacheOnDisc().build();

        TabHost tabs=(TabHost)findViewById(android.R.id.tabhost);
        tabs.setup();

        TabSpec spec=tabs.newTabSpec("tag1");
        spec.setContent(R.id.slidetab);
        spec.setIndicator("Slideshow");
        tabs.addTab(spec);

        TabSpec spec2=tabs.newTabSpec("tag2");
        spec2.setContent(R.id.edittab);
        spec2.setIndicator("Edit");
        tabs.addTab(spec2);

        images = (DraggableGridView)findViewById(R.id.editGrid);          
        this.imageCursor = this.mdbAdapter.getShowCursor(strid);
        this.imageArray = new ArrayList<String>();
        imageCursor.moveToFirst();
        imageArray.add(imageCursor.getString(imageCursor.getColumnIndex("url")));
        while (imageCursor.moveToNext()) 
        {
           imageArray.add(imageCursor.getString(imageCursor.getColumnIndex("url")));
        }
        int i = this.imageArray.size();
        for (int j = 0; j < i; j++)
        {
          ImageView localImageView1 = new ImageView(ImageGrid.this);
          localImageView1.setScaleType(ImageView.ScaleType.CENTER_CROP);
          localImageView1.setImageBitmap(ImageGrid.this.mLoder.getBitmap((String)this.imageArray.get(j), 300, 300));
          ImageGrid.this.images.addView(localImageView1);
            //Toast.makeText(getApplicationContext(), " url" + imageArray.get(j), Toast.LENGTH_LONG).show();
        }

        grid =(GridView)findViewById(R.id.photogrid);
        this.mAdapter = new MyAdapter(this, this.mdbAdapter.getShowCursor(strid)); 
        this.grid.setAdapter(this.mAdapter);

错误在行 localImageView1.setImageBitmap(ImageGrid.this.mLoder.getBitmap((String)this.imageArray.get(j), 300, 300));

我的日志如下

 11-28 11:26:10.646: E/AndroidRuntime(23972): FATAL EXCEPTION: main
11-28 11:26:10.646: E/AndroidRuntime(23972): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.application1/com.example.application1.ImageGrid}: java.lang.NullPointerException
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.app.ActivityThread.access$600(ActivityThread.java:149)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.os.Looper.loop(Looper.java:153)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.app.ActivityThread.main(ActivityThread.java:5086)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at java.lang.reflect.Method.invokeNative(Native Method)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at java.lang.reflect.Method.invoke(Method.java:511)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at dalvik.system.NativeStart.main(Native Method)
11-28 11:26:10.646: E/AndroidRuntime(23972): Caused by: java.lang.NullPointerException
11-28 11:26:10.646: E/AndroidRuntime(23972):    at com.example.application1.ImageGrid.onCreate(ImageGrid.java:109)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.app.Activity.performCreate(Activity.java:5020)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-28 11:26:10.646: E/AndroidRuntime(23972):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
11-28 11:26:10.646: E/AndroidRuntime(23972):    ... 11 more

xml文件是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/page3">

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                 >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent" 
                android:layout_marginTop="10dp">

                    <LinearLayout
                        android:id="@+id/slidetab"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:orientation="vertical">                     
                            <GridView 
                                android:gravity="center" 
                                android:id="@+id/photogrid" 
                                android:scrollbars="vertical" 
                                android:layout_width="fill_parent" 
                                android:layout_height="match_parent" 
                                android:horizontalSpacing="4.0dip" 
                                android:verticalSpacing="10.0dip" 
                                android:stretchMode="columnWidth" 
                                android:columnWidth="100.0dip" 
                                android:numColumns="2" 
                                android:layout_weight="1.0" />
                            <Button 
                                android:layout_gravity="center" 
                                android:id="@+id/play" 
                                android:background="@drawable/slideshow1" 
                                android:layout_width="wrap_content" 
                                android:layout_height="wrap_content" 
                                />                      
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/edittab"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:orientation="vertical">
                            <LinearLayout
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:orientation="horizontal">
                                    <Button
                                        android:layout_width="150dp"
                                        android:layout_height="50dp"
                                        android:id="@+id/addImage"
                                        android:text="Add Images"
                                        android:layout_marginLeft="10dp"></Button>
                                    <Button
                                        android:layout_width="150dp"
                                        android:layout_height="50dp"
                                        android:id="@+id/addMusic"
                                        android:text="Add Images"></Button>
                            </LinearLayout>
                            <LinearLayout 
                                android:layout_width="fill_parent"
                                android:layout_height="match_parent"
                                android:orientation="vertical">

                            <com.example.application1.views.DraggableGridView
                                        android:id="@+id/editGrid"
                                        android:layout_width="fill_parent"
                                        android:layout_height="wrap_content"
                                        android:layout_marginTop="10dp"
                                        android:scrollbarStyle="insideOverlay"
                                        android:scrollbars="vertical"
                                        android:background="#CCCCCC"
                              />
                            <Button
                                android:id="@+id/update"
                                 android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="5dp"
                                android:text="Update"/>
                            </LinearLayout>
                    </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>      
</LinearLayout>

我无法找出解决方案,请帮忙。谢谢。

最佳答案

在任何地方使用之前,只需初始化 mLoder

关于android - java.lang.RuntimeException : Unable to start activity ComponentInfo 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27183220/

相关文章:

android - 如何以编程方式删除我的 NestedScrollView 的布局行为?

android - eclipse 找不到 android.support.v4.widget.SwipeRefreshLayout

java - 单击 JDialog 中的“取消”按钮时出现异常

java - Eclipse 中的 NullPointerException 但不在命令提示符中

android - 尝试在 LG G Watch 上录制音频时,MediaRecorder 抛出 "java.lang.RuntimeException: start failed: -2147483648"

java - 相机关闭虚拟机 - java.lang.RuntimeException : setParameters failed

android - 更新数据库时出现 CursorIndexOutOfBoundsException

android - cvc-complex-type.2.4.a : Invalid content was found starting with element 'base-extension' . 预期为 '{layoutlib}' 之一

java - 如果我不在表中输入任何值或将任何行留空,则会出现 NullPointerException

c# - 尝试插入数据时出现运行时错误