2011-02-03 51 views
0

你好,我有我的短信應用程序的問題。短信應用程序 - 錯誤

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/5第43行的Java問題。

有人可以幫助我嗎?

回答

0

看起來你沒有重命名你的模板方法的Eclipse放在你的參數,嘗試改變:

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

要:

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

非常感謝您! – Adam 2011-02-03 20:17:52