我制作了 2 个应用程序:ave
和xvf
. 从 开始ave
,我调用了一个意图来打开Thumbs
里面的类,xvf
如下所示:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.floritfoto.apps.xvf", "com.floritfoto.apps.xvf.Thumbs");
intent.putExtra("files", imgfiles);
startActivity(intent);
安装了 2 个应用程序后,这就像一个魅力,世界很开心。
现在我创建了xvf
一个库以避免安装这两个应用程序。我现在Thumbs
这样打电话:
Intent intent = new Intent(getBaseContext(), com.floritfoto.apps.xvf.Thumbs.class);
intent.putExtra("files", imgfiles);
startActivity(intent);
好吧,这是行不通的,因为我NullPointerException
在上面写了一行Thumbs
:
gridview.setNumColumns(3);
gridview 是一个 GridView,它是在from 其布局的onCreate()
方法中创建的。Thumbs
我的第六感告诉我,这个问题与上下文有关。也许在getBaseContext()
调用意图时?我应该放什么?(抱歉,这个新手不太懂这个context
东西……)
我包括崩溃日志:
12-22 13:54:20.890: W/dalvikvm(29093): threadid=1: thread exiting with uncaught exception (group=0x40c531f8)
12-22 13:54:20.895: E/AndroidRuntime(29093): FATAL EXCEPTION: main
12-22 13:54:20.895: E/AndroidRuntime(29093): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.floritfoto.apps.ave/com.floritfoto.apps.xvf.Thumbs}: java.lang.NullPointerException
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.app.ActivityThread.access$600(ActivityThread.java:127)
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.os.Looper.loop(Looper.java:137)
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.app.ActivityThread.main(ActivityThread.java:4507)
12-22 13:54:20.895: E/AndroidRuntime(29093): at java.lang.reflect.Method.invokeNative(Native Method)
12-22 13:54:20.895: E/AndroidRuntime(29093): at java.lang.reflect.Method.invoke(Method.java:511)
12-22 13:54:20.895: E/AndroidRuntime(29093): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
12-22 13:54:20.895: E/AndroidRuntime(29093): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
12-22 13:54:20.895: E/AndroidRuntime(29093): at dalvik.system.NativeStart.main(Native Method)
12-22 13:54:20.895: E/AndroidRuntime(29093): Caused by: java.lang.NullPointerException
12-22 13:54:20.895: E/AndroidRuntime(29093): at com.floritfoto.apps.xvf.Thumbs.numcols(Thumbs.java:70)
12-22 13:54:20.895: E/AndroidRuntime(29093): at com.floritfoto.apps.xvf.Thumbs.onCreate(Thumbs.java:110)
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.app.Activity.performCreate(Activity.java:4465)
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
12-22 13:54:20.895: E/AndroidRuntime(29093): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
12-22 13:54:20.895: E/AndroidRuntime(29093): ... 11 more