0

こんにちは、スピナー (リスト ビュー) からデータを選択し、値を選択するアプリを作成しています。これは私のログ猫情報です

 08-25 09:13:28.786: W/dalvikvm(580): threadid=1: thread exiting with uncaught exception (group=0x40015560)
 08-25 09:13:28.892: E/AndroidRuntime(580): FATAL EXCEPTION: main
 08-25 09:13:28.892: E/AndroidRuntime(580): java.lang.NullPointerException
 08-25 09:13:28.892: E/AndroidRuntime(580):     at com.example.dcsd.Result$1.onClick(Result.java:44)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at android.view.View.performClick(View.java:2485)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at android.view.View$PerformClick.run(View.java:9080)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at android.os.Handler.handleCallback(Handler.java:587)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at android.os.Handler.dispatchMessage(Handler.java:92)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at android.os.Looper.loop(Looper.java:123)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at android.app.ActivityThread.main(ActivityThread.java:3683)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at java.lang.reflect.Method.invokeNative(Native Method)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at java.lang.reflect.Method.invoke(Method.java:507)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at        com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 08-25 09:13:28.892: E/AndroidRuntime(580):     at dalvik.system.NativeStart.main(Native Method)

そして、これは私の Result.java クラスです

 package com.example.dcsd;

 import java.util.ArrayList;
 import java.util.List;

 import android.app.ListActivity;
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.View.OnClickListener;
 import android.widget.AdapterView.OnItemSelectedListener;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.ListView;
 import android.widget.Spinner;
 import android.widget.TextView;

 public class Result extends ListActivity{
Spinner sp;
SpinnerWrapper wrapper=new SpinnerWrapper();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.result);
    MyAdapter adap=new MyAdapter(this, android.R.layout.simple_list_item_1,R.id.textView1, getResources().getStringArray(R.array.modules));
    setListAdapter(adap);
    Button b=(Button) findViewById(R.id.button12);
    final Spinner sp=(Spinner) findViewById(R.id.spinner1);
    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent=new Intent(Result.this,Cal.class);
            for(int i=0;i<15;i++){
                //String text= sp.getSelectedItem().toString();
                //Log.d("This", "huu");
            }
            sp.setOnItemSelectedListener(wrapper);
            //intent.putExtra("values", sp.getSelectedItem().toString());
            //intent.putExtra("values", sp.setOnItemSelectedListener(wrapper));
            startActivity(intent);              
        }
    });
}

private class MyAdapter extends ArrayAdapter<String>{

    public MyAdapter(Context context, int resource, int textViewResourceId,
            String[] strings) {
        super(context, resource, textViewResourceId, strings);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row=inflater.inflate(R.layout.item_layout, parent,false);
        String[] items=getResources().getStringArray(R.array.modules);
        TextView tv=(TextView) row.findViewById(R.id.textView1);        
        tv.setText(items[position]);
        sp=(Spinner)row.findViewById(R.id.spinner1);
        ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(Result.this, R.array.grades, android.R.layout.simple_spinner_dropdown_item);
        sp.setAdapter(adapter);
        //sp.setOnItemSelectedListener(wrapper);
        //int dd=row.getId();
        return row;     
    }
}
 }

そして、私の SpinnerWrapper.java クラスはこのようにロックします

 package com.example.dcsd;

 import android.util.Log;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemSelectedListener;

 public class SpinnerWrapper implements OnItemSelectedListener {

public SpinnerWrapper() {

}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
        long id) {
     String tex=parent.getItemAtPosition(position).toString();
     Log.d("Selected", tex);

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}

 }

どうすればこの問題を解決できますか??

4

1 に答える 1