程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> final- Could not execute method of the activity

final- Could not execute method of the activity

編輯:編程綜合問答
Could not execute method of the activity

XML中有3個按鈕,實現後出現空指針,代碼如下
item.XML

 <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/on"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/off"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/voice" />
            </LinearLayout>
        </LinearLayout>

main.java

 public class MainActivity extends FragmentActivity {
    public static Context context;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        GridView list = (GridView) findViewById(R.id.list);
        MyAdapter gAdapter = new MyAdapter(dev_list, this);
        list.setAdapter(gAdapter);
        final Integer[] images = new Integer[]{R.id.on, R.id.off, R.id.voice};
        dev_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (images[position]) {
                    case R.id.on:
                        Toast.makeText(getApplicationContext(), "說話",
                                Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.off:
                        Toast.makeText(getApplicationContext(), "停止",
                                Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.voice:
                        Toast.makeText(getApplicationContext(), "聽話",
                                Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
    }

求指點,盡量詳細的,腦子不太夠用

最佳回答:


關系有點亂

 GridView list = (GridView) findViewById(R.id.list);  //這是gridview
        MyAdapter gAdapter = new MyAdapter(dev_list, this);  //adapter
        list.setAdapter(gAdapter);    //gridview和adapter
        final Integer[] images = new Integer[]{R.id.on, R.id.off, R.id.voice};
        dev_list.setOnItemClickListener  //這裡怎麼監聽dev_list?這個adapter和gridview什麼關系
llx2007
llx2007
llx2007
danielinbiti
llx2007
llx2007
danielinbiti
llx2007
danielinbiti
llx2007
llx2007
danielinbiti
llx2007
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved