按钮Onclick适用于api 25,但失败了api 18 - Android Studio

时间:2017-02-05 00:54:21

标签: android android-intent

intent = new intent()行失败。请帮助我。

Intent intent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

public void buttonTapped(View view){
    int id = view.getId();
    String ourId = "";
    ourId = view.getResources().getResourceEntryName((id));

    intent = new Intent(getApplicationContext(), aboutUsActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getApplicationContext().startActivity(intent);

    //Log.i("button tapped", ourId);
}
  

E / AndroidRuntime:致命异常:主要                     java.lang.IllegalStateException:无法执行android:onClick的方法                         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)                         在android.view.View.performClick(View.java:4240)                         在android.view.View $ PerformClick.run(View.java:17721)                         在android.os.Handler.handleCallback(Handler.java:730)                         在android.os.Handler.dispatchMessage(Handler.java:92)                         在android.os.Looper.loop(Looper.java:137)                         在android.app.ActivityThread.main(ActivityThread.java:5103)                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:525)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)                         at dalvik.system.NativeStart.main(Native Method)                      引起:java.lang.reflect.InvocationTargetException                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:525)                         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)                         在android.view.View.performClick(View.java:4240)                         在android.view.View $ PerformClick.run(View.java:17721)                         在android.os.Handler.handleCallback(Handler.java:730)                         在android.os.Handler.dispatchMessage(Handler.java:92)                         在android.os.Looper.loop(Looper.java:137)                         在android.app.ActivityThread.main(ActivityThread.java:5103)                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:525)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)                         at dalvik.system.NativeStart.main(Native Method)                      引起:java.lang.NullPointerException                         在com.kshakoor.iiql.MainActivity.buttonTapped(MainActivity.java:68)                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:525)                         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)                         在android.view.View.performClick(View.java:4240)                         在android.view.View $ PerformClick.run(View.java:17721)                         在android.os.Handler.handleCallback(Handler.java:730)                         在android.os.Handler.dispatchMessage(Handler.java:92)                         在android.os.Looper.loop(Looper.java:137)                         在android.app.ActivityThread.main(ActivityThread.java:5103)                         at java.lang.reflect.Method.invokeNative(Native Method)                         在java.lang.reflect.Method.invoke(Method.java:525)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)                         在dalvik.system.NativeStart.main(本地方法)

申请已终止。

0 个答案:

没有答案