java
1 obj2.put("Password", Password); 2 obj2.put("UserName",UserName);
このようなコードではcan not resolve symbol Password,UserNameとなります。
どうすれば、この下の、xmlのPasswordとUserNameをputできるのでしょうか?
xml
1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" 5 android:layout_height="match_parent" 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 app:layout_behavior="@string/appbar_scrolling_view_behavior" 10 tools:showIn="@layout/activity_activity_second" 11 tools:context="ncmbdataquick.mbaas.com.nifty.datastorequickstart.ActivitySecond"> 12 13 <Button 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:text="登録する" 17 android:onClick="NewUserSet" 18 android:id="@+id/NewUserSet" 19 android:layout_centerVertical="true" 20 android:layout_alignLeft="@+id/ToLogin" 21 android:layout_alignStart="@+id/ToLogin" /> 22 23 <Button 24 android:layout_width="wrap_content" 25 android:layout_height="wrap_content" 26 android:text="ログインして始める" 27 android:id="@+id/ToLogin" 28 android:layout_below="@+id/NewUserSet" 29 android:layout_centerHorizontal="true" 30 android:layout_marginTop="59dp" /> 31 32 <EditText 33 android:layout_width="wrap_content" 34 android:layout_height="wrap_content" 35 android:inputType="textPassword" 36 android:ems="10" 37 android:id="@+id/Password" 38 android:layout_above="@+id/NewUserSet" 39 android:layout_alignRight="@+id/ToLogin" 40 android:layout_alignEnd="@+id/ToLogin" /> 41 42 <TextView 43 android:layout_width="wrap_content" 44 android:layout_height="wrap_content" 45 android:textAppearance="?android:attr/textAppearanceSmall" 46 android:text="Passeword" 47 android:id="@+id/textView" 48 android:layout_above="@+id/Password" 49 android:layout_alignLeft="@+id/Password" 50 android:layout_alignStart="@+id/Password" /> 51 52 <TextView 53 android:layout_width="wrap_content" 54 android:layout_height="wrap_content" 55 android:textAppearance="?android:attr/textAppearanceSmall" 56 android:text="UserName" 57 android:id="@+id/textView2" 58 android:layout_alignParentTop="true" 59 android:layout_alignLeft="@+id/textView" 60 android:layout_alignStart="@+id/textView" /> 61 62 <EditText 63 android:layout_width="wrap_content" 64 android:layout_height="wrap_content" 65 android:inputType="textPersonName" 66 android:ems="10" 67 android:id="@+id/UserName" /> 68 69</RelativeLayout> 70 71
ActivitySecond.java
java
1package ncmbdataquick.mbaas.com.nifty.datastorequickstart; 2 3import android.app.Activity; 4import android.app.AlertDialog; 5import android.content.Intent; 6import android.os.Bundle; 7import android.support.design.widget.FloatingActionButton; 8import android.support.design.widget.Snackbar; 9import android.support.v7.app.AppCompatActivity; 10import android.support.v7.widget.Toolbar; 11import android.view.View; 12import android.widget.Button; 13 14import com.nifty.cloud.mb.core.DoneCallback; 15import com.nifty.cloud.mb.core.NCMB; 16import com.nifty.cloud.mb.core.NCMBException; 17import com.nifty.cloud.mb.core.NCMBObject; 18 19import javax.security.auth.callback.PasswordCallback; 20 21public class ActivitySecond extends Activity { 22 @Override 23 protected void onCreate(Bundle savedInstanceState) { 24 super.onCreate(savedInstanceState); 25 setContentView(R.layout.activity_activity_second); 26 27 28 //**************** APIキーの設定とSDKの初期化 ********************** 29 NCMB.initialize(this, ""); 30 31 32 Button sendButton = (Button) findViewById(R.id.ToLogin); 33 sendButton.setOnClickListener(new View.OnClickListener() { 34 35 36 @Override 37 38 39 public void onClick(View v) { 40 Intent intent = new Intent(getApplication(), MainActivity.class); 41 startActivity(intent); 42 43 44 45 } 46 }); 47 } 48 49 50 //このメソッドを呼び出せば、PasswordとUserIdがセットされるようにする。 51 //xmlにonClickでNewUserSetを記入しておく 52 53 public void NewUserSet(View view) { 54 55 //NewUserAddというデータベースのクラス 56 final NCMBObject obj2 = new NCMBObject("NewUserAdd"); 57 //ここをPlanText(TextView)にユーザーが打ち込んだ値にする。 58 obj2.put("Password", Password); 59 obj2.put("UserName",UserName); 60 obj2.saveInBackground(new DoneCallback() { 61 @Override 62 public void done(NCMBException e) { 63 if (e != null) { 64 //保存失敗 65 new AlertDialog.Builder(ActivitySecond.this) 66 .setTitle("Notification from Nifty") 67 .setMessage("Error:" + e.getMessage()) 68 .setPositiveButton("OK", null) 69 .show(); 70 71 } else { 72 //保存成功 73 new AlertDialog.Builder(ActivitySecond.this) 74 .setTitle("Notification from Nifty") 75 .setMessage("Save successfull! with ID:" + obj2.getObjectId()) 76 .setPositiveButton("OK", null) 77 .show(); 78 79 } 80 } 81 }); 82 83 } 84 85 86} 87
どうぞ宜しくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/31 06:24
2016/10/31 07:01