DineOutActivity.java と Userpersonal .java の 2 つのクラスがあります。DineOutActivity.java でスピナー (spinner1) が定義されています。
私はメソッドを作成しているので、UserPersonal.javaの画像をクリックします
そしてスピナーメソッドを呼び出します。DineOutActivity.java の spinner1 をクリックして User Personal.java に移動し、[送信] をクリックすると、別のページにリダイレクトされます。
ここに私のDineOutActivity.javaがあります
public class DineOutActivity extends Activity {
Spinner sp;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/********************spinner***********/
Spinner food = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> foodadapter = ArrayAdapter.createFromResource(
this, R.array.item_array, android.R.layout.simple_spinner_item);
foodadapter.setDropDownViewResource(R.layout.spinner_layout);
food.setAdapter(foodadapter);
}
これは私の UsePersonal.java です
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userpersonal);
}
public void spinner()
{ DineOutActivity doa = new DineOutActivity() ;
Spinner food = doa.sp;
food.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
if(pos ==3)
{
Intent select = new Intent();
select.setClass(getBaseContext(), PizzaHut.class);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public void onClick(View view)
{ spinner();
}
05-04 18:49:32.617: E/AndroidRuntime(24237): FATAL EXCEPTION: main
05-04 18:49:32.617: E/AndroidRuntime(24237): java.lang.IllegalStateException: Could not execute method of the activity
05-04 18:49:32.617: E/AndroidRuntime(24237): at android.view.View$1.onClick(View.java:2144)
05-04 18:49:32.617: E/AndroidRuntime(24237): at android.view.View.performClick(View.java:2485)
05-04 18:49:32.617: E/AndroidRuntime(24237): at android.view.View$PerformClick.run(View.java:9080)
05-04 18:49:32.617: E/AndroidRuntime(24237): at android.os.Handler.handleCallback(Handler.java:587)
05-04 18:49:32.617: E/AndroidRuntime(24237): at android.os.Handler.dispatchMessage(Handler.java:92)
05-04 18:49:32.617: E/AndroidRuntime(24237): at android.os.Looper.loop(Looper.java:130)
05-04 18:49:32.617: E/AndroidRuntime(24237): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-04 18:49:32.617: E/AndroidRuntime(24237): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 18:49:32.617: E/AndroidRuntime(24237): at java.lang.reflect.Method.invoke(Method.java:507)
05-04 18:49:32.617: E/AndroidRuntime(24237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-04 18:49:32.617: E/AndroidRuntime(24237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-04 18:49:32.617: E/AndroidRuntime(24237): at dalvik.system.NativeStart.main(Native Method)
05-04 18:49:32.617: E/AndroidRuntime(24237): Caused by: java.lang.reflect.InvocationTargetException
05-04 18:49:32.617: E/AndroidRuntime(24237): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 18:49:32.617: E/AndroidRuntime(24237): at java.lang.reflect.Method.invoke(Method.java:507)
05-04 18:49:32.617: E/AndroidRuntime(24237): at android.view.View$1.onClick(View.java:2139)
05-04 18:49:32.617: E/AndroidRuntime(24237): ... 11 more
05-04 18:49:32.617: E/AndroidRuntime(24237): Caused by: java.lang.NullPointerException
05-04 18:49:32.617: E/AndroidRuntime(24237): at com.crews.dineout.UserPersonal.spinner(UserPersonal.java:63)
05-04 18:49:32.617: E/AndroidRuntime(24237): at com.crews.dineout.UserPersonal.onClick(UserPersonal.java:83)
05-04 18:49:32.617: E/AndroidRuntime(24237): ... 14 more
UserPersonal.java food.setOnItemSelectedListener(new OnItemSelectedListener() {