如何阻止genyMotion崩溃意图?

时间:2015-08-20 00:39:03

标签: android android-intent genymotion

所以我使用了genyMotion模拟器,但是我有一些我不能立即使用的意图,并且不知何故它继续崩溃(并且给我一个空指针异常)!在我真正的Android设备上运行正常,我没有得到例外..这里是一些示例代码。有人可以帮助PLZ!?!?

public class MyActivity extends Activity implements View.OnClickListener {


    private Intent storeRightintent = new Intent(this, Istanbul_Folder.class);//I KEEP GETTING NULL POINT EXCEPTION HERE!!!


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        ButterKnife.inject(this);

        storeRightintent = new Intent(this, Istanbul_Folder.class);

        //Buttons
        View folderButton = (View) findViewById(R.id.folder_button);
        folderButton.setOnClickListener((View.OnClickListener) this);
        View createButton = (View) findViewById(R.id.MycreateButton);
        createButton.setOnClickListener(this);

    }

logcat的:

Process: com.lorentzos.swipecards.example, PID: 7303
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.lorentzos.swipecards.example/com.lorentzos.swipecards.MyActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at android.content.ContextWrapper.getPackageName(ContextWrapper.java:135)
            at android.content.ComponentName.<init>(ComponentName.java:77)
            at android.content.Intent.<init>(Intent.java:3813)
            at com.lorentzos.swipecards.MyActivity.<init>(MyActivity.java:45)
            at java.lang.Class.newInstanceImpl(Native Method)
            at java.lang.Class.newInstance(Class.java:1208)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

更改private Intent storeRightintent = new Intent(this, Istanbul_Folder.class);//I KEEP GETTING NULL POINT EXCEPTION HERE!!!private Intent storeRightintent;

因为我怀疑,该行的this尚未初始化。