ページ遷移を設定しようとしているのですが、
ボタンを押すとクラッシュします。
どうすればいいですか?
JAVA
1package com.nifty.user; 2 3import android.content.Intent; 4import android.os.Bundle; 5import android.support.v7.app.ActionBarActivity; 6import android.view.Menu; 7import android.view.MenuItem; 8import android.view.View; 9 10import com.nifty.cloud.mb.core.DoneCallback; 11import com.nifty.cloud.mb.core.NCMB; 12import com.nifty.cloud.mb.core.NCMBException; 13import com.nifty.cloud.mb.core.NCMBUser; 14 15public class MainActivity extends ActionBarActivity { 16 17 @Override 18 protected void onCreate(Bundle savedInstanceState) { 19 super.onCreate(savedInstanceState); 20 setContentView(R.layout.activity_main); 21 22 23 //**************** APIキーの設定とSDKの初期化 ********************** 24 NCMB.initialize(this, "CODE", "CODE"); 25 26 Intent intent = new Intent(this, LoginActivity.class); 27 startActivity(intent); 28 29 } 30 31 // クリック処理 32 public void onButton( View v){ 33 Intent intent = new Intent(this,MusicWebActivity.class); // 画面指定 34 startActivity(intent); // 画面を開く 35 } 36 37 @Override 38 public boolean onCreateOptionsMenu(Menu menu) { 39 // Inflate the menu; this adds items to the action bar if it is present. 40 getMenuInflater().inflate(R.menu.menu_main, menu); 41 return true; 42 } 43 44 @Override 45 public boolean onOptionsItemSelected(MenuItem item) { 46 // Handle action bar item clicks here. The action bar will 47 // automatically handle clicks on the Home/Up button, so long 48 // as you specify a parent activity in AndroidManifest.xml. 49 int id = item.getItemId(); 50 51 //noinspection SimplifiableIfStatement 52 if (id == R.id.action_settings) { 53 return true; 54 } 55 56 if (id == R.id.action_logout) { 57 NCMBUser.logoutInBackground(new DoneCallback() { 58 @Override 59 public void done(NCMBException e) { 60 if (e != null) { 61 //エラー時の処理 62 } 63 } 64 }); 65 Intent intent = new Intent(this, LoginActivity.class); 66 startActivity(intent); 67 return true; 68 } 69 70 return super.onOptionsItemSelected(item); 71 } 72 73} 74
XML
1<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:paddingLeft="@dimen/activity_horizontal_margin" 6 android:paddingRight="@dimen/activity_horizontal_margin" 7 android:paddingTop="@dimen/activity_vertical_margin" 8 android:paddingBottom="@dimen/activity_vertical_margin" 9 tools:context=".MainActivity"> 10 11 <TextView android:text="ご利用くださりましてありがとうございます。ただいま、ご利用いただけるサービスや実施中の企画をご紹介しております。" android:layout_width="wrap_content" 12 android:layout_height="wrap_content" 13 android:id="@+id/textView" /> 14 15 <ImageButton 16 android:layout_width="wrap_content" 17 android:layout_height="wrap_content" 18 android:id="@+id/imageButton" 19 android:nestedScrollingEnabled="false" 20 android:src="@drawable/logo" 21 android:layout_below="@+id/textView" 22 android:layout_alignParentLeft="true" 23 android:layout_alignParentStart="true" 24 android:layout_marginTop="42dp" 25 android:onClick="onButton"/> 26 27</RelativeLayout> 28
エラーログです。
09-11 03:36:28.746 1394-1394/com.sourcey.user E/AndroidRuntime: FATAL EXCEPTION: main Process: com.sourcey.user, PID: 1394 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sourcey.user/com.nifty.user.MusicWebActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 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 com.nifty.user.MusicWebActivity.onCreate(MusicWebActivity.java:15) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 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)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/11 07:50