问题描述
我知道这个帖子是这样的问题:如何获得安装媒体播放器的列表但我想,以测试code和崩溃!这是code:
I know that this post is like this question :How to get a list of installed media playersbut i tried to test the code and it crashes !this is the code :
public class Newactivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(MediaStore.Video.Media.INTERNAL_CONTENT_URI,"1");
intent.setData(uri);
List<ResolveInfo> playerList;
PackageManager packageManager = null;
playerList = packageManager.queryIntentActivities(intent, 0);
}
这是logcat的错误:
this is logcat errors:
10-19 13:05:52.770: E/AndroidRuntime(558): FATAL EXCEPTION: main
10-19 13:05:52.770: E/AndroidRuntime(558): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.upnpexample/com.upnpexample.Newactivity}: java.lang.NullPointerException
10-19 13:05:52.770: E/AndroidRuntime(558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
10-19 13:05:52.770: E/AndroidRuntime(558): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-19 13:05:52.770: E/AndroidRuntime(558): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-19 13:05:52.770: E/AndroidRuntime(558): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-19 13:05:52.770: E/AndroidRuntime(558): at android.os.Handler.dispatchMessage(Handler.java:99)
10-19 13:05:52.770: E/AndroidRuntime(558): at android.os.Looper.loop(Looper.java:123)
10-19 13:05:52.770: E/AndroidRuntime(558): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-19 13:05:52.770: E/AndroidRuntime(558): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 13:05:52.770: E/AndroidRuntime(558): at java.lang.reflect.Method.invoke(Method.java:507)
10-19 13:05:52.770: E/AndroidRuntime(558): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-19 13:05:52.770: E/AndroidRuntime(558): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-19 13:05:52.770: E/AndroidRuntime(558): at dalvik.system.NativeStart.main(Native Method)
10-19 13:05:52.770: E/AndroidRuntime(558): Caused by: java.lang.NullPointerException
10-19 13:05:52.770: E/AndroidRuntime(558): at com.upnpexample.Newactivity.onCreate(Newactivity.java:31)
10-19 13:05:52.770: E/AndroidRuntime(558): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-19 13:05:52.770: E/AndroidRuntime(558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-19 13:05:52.770: E/AndroidRuntime(558): ... 11 more
任何想法吗?
any idea please ?
推荐答案
可能没有在该乌里
任何内容,因为你是做不起来。请使用乌里
来的内容的真实作品。
There may not be any content at that Uri
, since you are making it up. Please use a Uri
to an actual piece of content.
除此之外,检查LogCat中的堆栈跟踪,看看有什么你可能是做错了。
Beyond that, examine the stack trace in LogCat to see what you may be doing wrong.
更新
PackageManager packageManager = null;
playerList = packageManager.queryIntentActivities(intent, 0);
由于 packageManager
是空
,你会得到一个 NullPointerException异常
在这里。使用 getPackageManager()
来获取一个实例 PackageManager
。
Since packageManager
is null
, you will get a NullPointerException
here. Use getPackageManager()
to get an instance of PackageManager
.
这篇关于安装媒体播放器的Android名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!