短信应用程序 - 错误

时间:2011-02-03 19:45:31

标签: android sms

您好我的短信应用程序有问题。

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;

import android.telephony.SmsManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class Smsfive extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState, ListView messages) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ListView list = (ListView) findViewById(R.id.list);
        List<String> msgList = getSMS();

        for(int i = 0; i<msgList.size(); i++) {
            System.out.println(msgList.get(i));
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.main, msgList); 



    list.setAdapter(adapter);
       list.setOnItemClickListener(new OnItemClickListener()
     {


            @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                SmsManager m = SmsManager.getDefault();

            String destinationNumber=(String) ((TextView)view).getText();              
             m.sendTextMessage(destinationNumber, null, destinationNumber, null, null);
        **there is Error ((TextView)view)**     
    }          
     });
  }

    public List<String> getSMS() {      
        List<String> list = new ArrayList<String>();
        Uri uri = Uri.parse("content://sms/inbox");
        Cursor c = null;
        try{
            c = getApplicationContext().getContentResolver().query(uri, null, null ,null,null); 
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            for (boolean hasData = c.moveToFirst(); hasData; hasData = c.moveToNext()) {
                final String address = c.getString(c.getColumnIndex("address"));
                final String body = c.getString(c.getColumnIndexOrThrow("body"));
                list.add("Number: " + address + ". Message: " + body);
            }
        }catch(Exception e){
            e.printStackTrace();
        }
     c.close(); 
     return list;
    }
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget30"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>

错误:说明资源路径位置类型 视图无法解析为变量Smsfive.java / Sms5 / src / sms / five line 43 Java问题。

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

看起来您没有重命名Eclipse为您输入的模板方法的参数,请尝试更改:

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)

要:

public void onItemClick(AdapterView<?> adapter, View view, int position, long id)