我搜索了这个并找到了许多解决方案,但它们都不适用于我。
我想从另一个包开始新的活动。我用这个
Intent myIntent = new Intent(this,my_class.class);
startActivityForResult(myIntent ,6161);
它给出了这个错误:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.xx.yy.pack/com.xx.yy.pack.my_class}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at java.io.File.fixSlashes(File.java:185)
at java.io.File.<init>(File.java:134)
at com.wub.cropimage.CropImage.a(Unknown Source)
at com.wub.cropimage.CropImage.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
... 11 more
我的清单在这里:
<activity
android:name="com.xx.yy.pack.my_class" >
<intent-filter>
<action android:name="myintent.intent.action.Launch" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
提前致谢
答案 0 :(得分:1)
就这样做
Intent myIntent = new Intent(this,my_class.class);
startActivity(myIntent);
在AndroidManifest.xml中执行此操作
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="Activity1"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.Activity2"></activity>
</application>
注意: - Activity1是您的第一个活动,Activity2是您的第二个活动 愿这可以帮到你
答案 1 :(得分:0)
从另一个包(应用程序)调用活动:
Intent myIntent = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getApplicationContext().getPackageManager();
myIntent = manager.getLaunchIntentForPackage(YourPackageName);
myIntent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivityForResult(myIntent ,6161);