Exception 微调器选择的选项必须存储在google表单中

Exception 微调器选择的选项必须存储在google表单中,exception,spinner,Exception,Spinner,主要活动 package com.example.wastewarriorsnew; public class MainActivity extends Activity implements OnItemSelectedListener { final String myTag = "DocsUpload"; String location,name,check_in,check_out,recy,nonrecy,recy_wt,nonrec_wt,new_loc,num,total_wt

主要活动

package com.example.wastewarriorsnew;

public class MainActivity extends Activity implements OnItemSelectedListener {

final String myTag = "DocsUpload";
String location,name,check_in,check_out,recy,nonrecy,recy_wt,nonrec_wt,new_loc,num,total_wt;
InputStream is=null;
String result=null;
String line=null;
int code;
String id;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Spinner element
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);

      // Spinner click listener
      spinner.setOnItemClickListener((OnItemClickListener) this);

      // Spinner Drop down elements
      List<String> categories = new ArrayList<String>();
      categories.add("Dehradun");
      categories.add("Pune");
      categories.add("Mumbai");
      categories.add("Delhi");
      categories.add("Goa");
      categories.add("Solapur");

      // Creating adapter for spinner
      ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);

      // Drop down layout style - list view with radio button
      dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

      // attaching data adapter to spinner
      spinner.setAdapter(dataAdapter);

    final EditText ed2 = (EditText)findViewById(R.id.workername);
    final EditText ed3 = (EditText)findViewById(R.id.Checkin);
    final EditText ed4 = (EditText)findViewById(R.id.Chechout);
    final EditText ed5 = (EditText)findViewById(R.id.Recycle);
    final EditText ed6 = (EditText)findViewById(R.id.NonRecycle);
    final EditText ed7 = (EditText)findViewById(R.id.Recycleweight);
    final EditText ed8 = (EditText)findViewById(R.id.Nonweight);
    final EditText ed9 = (EditText)findViewById(R.id.newlocation);
    final EditText ed10 = (EditText)findViewById(R.id.Number);
    final EditText ed11 = (EditText)findViewById(R.id.totalweight);


    final Button bt1=(Button)findViewById(R.id.button1);
bt1.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View arg0) {


        name=ed2.getText().toString();
        check_in=ed3.getText().toString();
        check_out=ed4.getText().toString();
        recy=ed5.getText().toString();
        nonrecy=ed6.getText().toString();
        recy_wt=ed7.getText().toString();
        nonrec_wt=ed8.getText().toString();
        new_loc=ed9.getText().toString();
        num=ed10.getText().toString();
        total_wt=ed11.getText().toString();

        Log.i(myTag, "OnCreate()");
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                postData();

            }
        });
        t.start();
        // TODO Auto-generated method stub

    }

});

}
public void postData() {

    String fullUrl = "https://docs.google.com/forms/d/e/1FAIpQLScXtmI3Ev-cxc04Ai5_6zmnudLoF6W9g/formResponse";
    HttpRequest mReq = new HttpRequest();


    final EditText ed2 = (EditText)findViewById(R.id.workername);
    final EditText ed3 = (EditText)findViewById(R.id.Checkin);
    final EditText ed4 = (EditText)findViewById(R.id.Chechout);
    final EditText ed5 = (EditText)findViewById(R.id.Recycle);
    final EditText ed6 = (EditText)findViewById(R.id.NonRecycle);
    final EditText ed7 = (EditText)findViewById(R.id.Recycleweight);
    final EditText ed8 = (EditText)findViewById(R.id.Nonweight);
    final EditText ed9 = (EditText)findViewById(R.id.newlocation);
    final EditText ed10 = (EditText)findViewById(R.id.Number);
    final EditText ed11 = (EditText)findViewById(R.id.totalweight);

    //String col1 = "Hello";
    //String col2 = "World";

    String data =// "entry.1178044604=" + URLEncoder.encode(location) + "&" + 
                  "entry.224535232=" + URLEncoder.encode(name)      + "&" +
                   "entry.829233547="+ URLEncoder.encode(check_in)  + "&" +
                    "entry.1814499237=" + URLEncoder.encode(check_out)+"&"+
                    "entry.1206946186="+ URLEncoder.encode(recy)+ "&" +
                  "entry.651664232=" + URLEncoder.encode(nonrecy) + "&" +
                    "entry.1115147786="+ URLEncoder.encode(recy_wt)+"&"+
                    "entry.472878985=" + URLEncoder.encode(nonrec_wt) +"&"+
                    "entry.1615743649="+ URLEncoder.encode(new_loc)+"&"+
                    "entry.2005603514="+ URLEncoder.encode(num)+"&"+
                    "entry.871683438="+ URLEncoder.encode(total_wt);

    String response = mReq.sendPost(fullUrl, data);
    Log.i(myTag, response);

}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    // TODO Auto-generated method stub
     // On selecting a spinner item
      String item = parent.getItemAtPosition(position).toString();

      // Showing selected spinner item
      Toast.makeText(parent.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

} 

}
package com.example.wastewarriorsnew;
公共类MainActivity扩展活动实现OnItemSelectedListener{
最后一个字符串myTag=“DocsUpload”;
字符串位置、名称、签入、签出、recy、NORECY、recy、NOREC、NOREC、new、num、total;
InputStream=null;
字符串结果=null;
字符串行=null;
int代码;
字符串id;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//旋转元件
微调器微调器=(微调器)findViewById(R.id.spinner1);
//微调器单击侦听器
spinner.setOnItemClickListener((OnItemClickListener)this);
//微调器下拉元素
列表类别=新建ArrayList();
类别。添加(“Dehradun”);
类别。添加(“普纳”);
类别。添加(“孟买”);
类别。添加(“德里”);
类别。添加(“Goa”);
类别。添加(“Solapur”);
//为微调器创建适配器
ArrayAdapter dataAdapter=新的ArrayAdapter(这是android.R.layout.simple\u微调器\u项,类别);
//下拉式布局样式-带单选按钮的列表视图
dataAdapter.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉项);
//将数据适配器连接到微调器
spinner.setAdapter(dataAdapter);
最终EditText ed2=(EditText)findViewById(R.id.workername);
最终EditText ed3=(EditText)findViewById(R.id.Checkin);
最终EditText ed4=(EditText)findViewById(R.id.Chechout);
最终EditText ed5=(EditText)findViewById(R.id.Recycle);
最终EditText ed6=(EditText)findViewById(R.id.NonRecycle);
最终EditText ed7=(EditText)findViewById(R.id.RecycleWight);
最终EditText ed8=(EditText)findViewById(R.id.Nonweight);
最终EditText ed9=(EditText)findViewById(R.id.newlocation);
最终EditText ed10=(EditText)findViewById(R.id.Number);
最终EditText ed11=(EditText)findViewById(R.id.totalweight);
最终按钮bt1=(按钮)findViewById(R.id.button1);
bt1.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图arg0){
name=ed2.getText().toString();
check_in=ed3.getText().toString();
check_out=ed4.getText().toString();
recy=ed5.getText().toString();
nonrecy=ed6.getText().toString();
recy_wt=ed7.getText().toString();
nonrec_wt=ed8.getText().toString();
new_loc=ed9.getText().toString();
num=ed10.getText().toString();
total_wt=ed11.getText().toString();
Log.i(myTag,“OnCreate()”);
线程t=新线程(新的可运行线程(){
@凌驾
公开募捐{
postData();
}
});
t、 start();
//TODO自动生成的方法存根
}
});
}
public void postData(){
字符串fullUrl=”https://docs.google.com/forms/d/e/1FAIpQLScXtmI3Ev-cxc04Ai5_6zmnudLoF6W9g/formResponse";
HttpRequest mReq=新的HttpRequest();
最终EditText ed2=(EditText)findViewById(R.id.workername);
最终EditText ed3=(EditText)findViewById(R.id.Checkin);
最终EditText ed4=(EditText)findViewById(R.id.Chechout);
最终EditText ed5=(EditText)findViewById(R.id.Recycle);
最终EditText ed6=(EditText)findViewById(R.id.NonRecycle);
最终EditText ed7=(EditText)findViewById(R.id.RecycleWight);
最终EditText ed8=(EditText)findViewById(R.id.Nonweight);
最终EditText ed9=(EditText)findViewById(R.id.newlocation);
最终EditText ed10=(EditText)findViewById(R.id.Number);
最终EditText ed11=(EditText)findViewById(R.id.totalweight);
//String col1=“Hello”;
//字符串col2=“世界”;
字符串数据=/“entry.1178044604=“+urlcoder.encode(位置)+”和“+
“entry.224535232=“+urlcoder.encode(名称)+”&”+
“entry.829233547=“+urlcoder.encode(签入)+”&”+
“entry.1814499237=“+urlcoder.encode(签出)+”&”+
“entry.1206946186=“+urlcoder.encode(recy)+”和”+
“entry.651664232=“+urlcoder.encode(非循环)+”和”+
“entry.1115147786=“+urlcoder.encode(recy_wt)+”&”+
“entry.472878985=“+URLEncoder.encode(nonrec_wt)+”&”+
“entry.1615743649=“+urlcoder.encode(新位置)+”&”+
“entry.2005603514=“+urlcoder.encode(num)+”和”+
“entry.871683438=“+urlcoder.encode(总重量);
字符串响应=mReq.sendPost(完整URL,数据);
Log.i(myTag,响应);
}
@凌驾
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
//TODO自动生成的方法存根
//关于选择微调器项
String item=parent.getItemAtPosition(position.toString();
//显示所选微调器项
Toast.makeText(parent.getContext(),“Selected:”+项,Toast.LENGTH_LONG.show();
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
} 
}
xml文件

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/scrollView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="@drawable/back" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="630dp"

android:orientation="vertical"
tools:context=".MainActivity" >

    <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="Location address"    />

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="Worker name"/>
    <EditText
    android:id="@+id/workername"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Worker Name"
    android:inputType="text" />

    <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="Check in"/>

<EditText
    android:id="@+id/Checkin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Check-in time"
    android:inputType="time" />

<TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="Check out"
      />

 <EditText
 android:id="@+id/Chechout"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:hint="Check-out time"
 android:inputType="time" />

 <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="No. of recyclable bags"
      />
 <EditText
   android:id="@+id/Recycle"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:hint="No of bags used for recyclable material"
   android:inputType="number" />

 <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="No. of non-recyclable bags"
      />
 <EditText
android:id="@+id/NonRecycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="No of bags used for non-recyclable material"
android:inputType="number" />

 <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="Wt. of recycle material"
      />
 <EditText
android:id="@+id/Recycleweight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Weight of recyclable material"
android:inputType="text" />

 <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="Wt. of non-recycle material"
      />
 <EditText
    android:id="@+id/Nonweight"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Weight of non-recyclable material"
    android:inputType="text" />

 <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="New location(if shifted)"
      />
 <EditText
    android:id="@+id/newlocation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="New location(if shifted)"
    android:inputType="text" />

 <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="No. of persons"
      />
 <EditText
    android:id="@+id/Number"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="No. of persons per loaction"
    android:inputType="number" />

 <TextView android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="Total weight"
      />
 <EditText
     android:id="@+id/totalweight"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:hint="Total weight of recyclable and non-recyclable material"
     android:inputType="number" />

 <LinearLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

 <Button
    android:id="@+id/button1"
    android:layout_width="80dp"
    android:layout_height="40dp"
    android:layout_marginLeft="40dp"
      android:layout_marginTop="50dp"
    android:text="Save" />

</LinearLayout>
</LinearLayout>
</ScrollView>

我在logcat中遇到的错误是:

08-03 04:49:03.828:E/AndroidRuntime(773):java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.example./com.exampleMainActivity}: java.lang.ClassCastException:com.example.main无法强制转换活动 到android.widget.AdapterView$McLickListener

但是现在logcat中没有msg,但是msg仍然是:

不幸的是,他停止了工作

当应用程序运行时,将从主活动添加详细信息,并单击保存按钮,它将存储在谷歌表单中。 帮帮我