gpt4 book ai didi

java - .资源$NotFoundException : String resource ID #0x3

转载 作者:行者123 更新时间:2023-11-29 03:22:54 31 4
gpt4 key购买 nike

在我的应用程序中,当我将一个 Intent 传递给另一个类时,以便用户可以发送短信并且该数据存储在数据库中,..当用户单击选择联系人按钮时,他会检查他发送的联系人消息,首先它工作正常但是当我在按钮上添加更新代码时单击它开始返回错误..并且 logcat 向我显示错误

03-24 11:45:10.811: E/AndroidRuntime(18748): android.content.res.Resources$NotFoundException: String resource ID #0x3
03-24 11:45:10.811: E/AndroidRuntime(18748): at android.widget.Toast.makeText(Toast.java:311)

短信发送.java

    public class SmsSend extends Activity implements OnClickListener {
BroadcastReceiver smsSentReciver, smsSentDelivery;
static EditText edName, edMessage;
static int ResultCode = 12;
static ArrayList<String> sendlist = new ArrayList<String>();
Button btnSaveForLater, btnStart, btnExternal, btnSelect;
static TextView txt;
static StringBuilder conct = new StringBuilder();
static String contacts = "";
String delim = ";";
public static String Name;
TextView ed;
int i = 0;
String rowid, rowid1, value;
int j;
String Name1, msg, msg1;
String[] cellArray;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.create_camp);


btnExternal.setOnClickListener(this);
txt = (TextView) findViewById(R.id.textnum2);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);

rowid = getIntent().getStringExtra("rowid");
value = getIntent().getStringExtra("key");
rowid1 = getIntent().getStringExtra("rowid1");
entryData();

edName.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
edName.setError(null);
}
});
edMessage.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
edMessage.setError(null);
}
});
txt.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
txt.setError(null);
}
});
// Toast.makeText(getApplication(), contacts.toString(),
// Toast.LENGTH_LONG).show();
Name1 = edName.getText().toString();

msg1 = edMessage.getText().toString();
}

@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
edName.setText(null);
edMessage.setText(null);
conct.delete(0, conct.length());
contacts = null;
txt.setText("0");
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
unregisterReceiver(smsSentReciver);
unregisterReceiver(smsSentDelivery);
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();

smsSentReciver = new BroadcastReceiver() {

@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "sms has been sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic Fail",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No Service",
Toast.LENGTH_SHORT).show();

default:
break;

}
}

};
smsSentDelivery = new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "Sms Delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "Sms not Delivered",
Toast.LENGTH_SHORT).show();
break;
}
}

};
registerReceiver(smsSentReciver, new IntentFilter("SMS_SENT"));
registerReceiver(smsSentDelivery, new IntentFilter("SMS_DELIVERED"));

}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DatabaseHelp entry = new DatabaseHelp(SmsSend.this);
entry.open();
switch (v.getId()) {

case R.id.btnSelect:

Intent a = new Intent(SmsSend.this, MainActivity.class);
startActivityForResult(a,ResultCode);
break;
case R.id.btnExternal:
Intent file = new Intent(SmsSend.this, File_Selecter.class);
startActivity(file);
break;



case R.id.btnStart:

Log.i("SMS", "Sendlist Size: " + sendlist.size());
if (edName.getText().toString().length() == 0
|| edName.getText().toString().length() == 0
|| txt.getText().equals("0")) {
edName.setError("First name is required!");
edMessage.setError("Message is required!");
txt.setError("Contacts required!");
} else {

/* if (rowid1 != null
&& edName.getText().toString().length() != 0
&& edName.getText().toString().length() != 0
&& txt.getText().equals("0")
&& edName.getText().toString() == value) {
Toast.makeText(getApplication(), "update", Toast.LENGTH_LONG).show();
SmsManager smsManager = SmsManager.getDefault();

PendingIntent piSend = PendingIntent.getBroadcast(this,
0, new Intent("SMS_SENT"), 0);
PendingIntent piDelivered = PendingIntent.getBroadcast(
this, 0, new Intent("SMS_DELIVERED"), 0);

Log.i("SMS", "contacts: " + contacts);

contacts = conct.toString();

cellArray = contacts.split(";");

for (int a1 = 0; a1 < cellArray.length; a1++) {

smsManager.sendTextMessage(cellArray[i].toString(),
null, msg1, piSend, piDelivered);

}
long ltt = Long.parseLong(rowid1);
entry.updateEntry(ltt, Name1, msg1, contacts);
Toast.makeText(getApplication(), "updated",
Toast.LENGTH_LONG).show();

} else {*/
boolean diditwork1 = true;
try {
Toast.makeText(getApplication(), "insert", Toast.LENGTH_LONG).show();

SmsManager smsManager = SmsManager.getDefault();

PendingIntent piSend = PendingIntent.getBroadcast(this,
0, new Intent("SMS_SENT"), 0);
PendingIntent piDelivered = PendingIntent.getBroadcast(
this, 0, new Intent("SMS_DELIVERED"), 0);

Log.i("SMS", "contacts: " + contacts);

contacts = conct.toString();
//Toast.makeText(getApplication(), contacts.toString(), Toast.LENGTH_LONG).show();
cellArray = contacts.split(";");
Toast.makeText(getApplication(), cellArray.length, Toast.LENGTH_LONG).show();
for (int a1 = 0; a1 < cellArray.length; a1++) {

smsManager.sendTextMessage(cellArray[i].toString(),
null, msg1, piSend, piDelivered);

}

DatabaseHelp entry1 = new DatabaseHelp(SmsSend.this);
entry1.open();

entry1.entryCreate(Name1, msg1, contacts);

entry1.close();
}
catch (Exception e) {
diditwork1 = false;
String erroe = e.toString();

Dialog d = new Dialog(this);
d.setTitle("Dang it!");
TextView tv = new TextView(this);
tv.setText(erroe);
d.setContentView(tv);
d.show();

} finally {
if (diditwork1) {
Dialog d = new Dialog(this);
d.setTitle("Heck Yeah!");
TextView tv = new TextView(this);
tv.setText("Success");
d.setContentView(tv);
d.show();
}
}

}

edName.setText("");
edMessage.setText("");
txt.setText("0");

break;
}
}
//}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == ResultCode) {

if (resultCode == RESULT_OK) {
sendlist = data.getStringArrayListExtra("name");
Toast.makeText(getApplication(), sendlist.size(), Toast.LENGTH_LONG).show();
if (sendlist != null) {

for (int i = 0; i < sendlist.size(); i++) {
conct.append(sendlist.get(i).toString());
conct.append(delim);
//Toast.makeText(getApplication(), conct.toString(),Toast.LENGTH_LONG).show();
}

}

}

i = sendlist.size();
txt.setText(Integer.toString(i));
if (resultCode == RESULT_CANCELED) {

}

}
}


}

MainaActiivty.java

    public class MainActivity extends Activity implements OnItemClickListener {

ArrayList<String> name1 = new ArrayList<String>();
static ArrayList<String> phno1 = new ArrayList<String>();
ArrayList<String> phno0 = new ArrayList<String>();
MyAdapter ma;
Button send;
String[] cellArray = null;
int[] str;
int v = 0;
String contacts;
static int check1;
ListView lv;
int index;
int top;
StringBuilder b = new StringBuilder();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.get);
// TextView txt = (TextView) findViewById(R.id.textView1);
getAllCallLogs(this.getContentResolver());
lv = (ListView) findViewById(R.id.lv);
ma = new MyAdapter();
lv.setAdapter(ma);
lv.setOnItemClickListener(this);
lv.setItemsCanFocus(false);
lv.setTextFilterEnabled(true);
// b = SmsSend.contacts;

contacts = SmsSend.contacts;
if (SmsSend.contacts != null) {
cellArray = contacts.split(";");
// Toast.makeText(getApplication(),contacts.toString(),
// Toast.LENGTH_LONG).show();
for (int i = 0; i < cellArray.length; i++) {

for (int j = 0; j < phno1.size(); j++) {

if (cellArray[i].equals(phno1.get(j))) {
Toast.makeText(getApplication(),cellArray[i].toString(),
Toast.LENGTH_LONG).show();
ma.setChecked(j, true);

}
}

}
}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.contact_main, menu);

return true;

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub

switch (item.getItemId()) {
case R.id.addPage:

break;

}
return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
// TODO Auto-generated method stub

StringBuilder checkedcontacts = new StringBuilder();
System.out.println(".............." + ma.mCheckStates.size());
for (int i = 0; i < name1.size(); i++)

{
if (ma.mCheckStates.get(i) == true) {
phno0.add(phno1.get(i).toString());
checkedcontacts.append(name1.get(i).toString());
checkedcontacts.append("\n");

} else {
System.out.println("..Not Checked......"
+ name1.get(i).toString());
}

}

Intent returnIntent = new Intent();
returnIntent.putStringArrayListExtra("name", phno0);
setResult(RESULT_OK, returnIntent);
Toast.makeText(getApplication(), phno0.size(), Toast.LENGTH_LONG).show();
finish();

}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
ma.toggle(arg2);

}

public void getAllCallLogs(ContentResolver cr) {

Cursor phones = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
+ " ASC");
while (phones.moveToNext()) {
String phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String name = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

System.out.println(phoneNumber);

name1.add(name);
phno1.add(phoneNumber);

}

phones.close();

}

class MyAdapter extends BaseAdapter implements
CompoundButton.OnCheckedChangeListener {
public SparseBooleanArray mCheckStates;
LayoutInflater mInflater;
TextView tv1, tv;
CheckBox cb;

MyAdapter() {
mCheckStates = new SparseBooleanArray(name1.size());
mInflater = (LayoutInflater) MainActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

// Save ListView state

@Override
public int getCount() {
// TODO Auto-generated method stub
return name1.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub

return position;
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub

return 0;
}

@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if (convertView == null)
vi = mInflater.inflate(R.layout.row, null);
tv = (TextView) vi.findViewById(R.id.textView1);
tv1 = (TextView) vi.findViewById(R.id.textView2);
cb = (CheckBox) vi.findViewById(R.id.checkBox1);
tv.setText(name1.get(position));
tv1.setText(phno1.get(position));
cb.setTag(position);

cb.setChecked(mCheckStates.get(position, false));
cb.setOnCheckedChangeListener(this);

return vi;

}

public boolean isChecked(int position) {

return mCheckStates.get(position, false);
}

public void setChecked(int position, boolean isChecked) {
mCheckStates.put(position, isChecked);
}

public void toggle(int position) {
setChecked(position, !isChecked(position));
}

@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
mCheckStates.put((Integer) buttonView.getTag(), isChecked);

}
}

}

最佳答案

试试这个:

Toast.makeText(getApplication(), sendlist.size().tostring(), Toast.LENGTH_LONG).show();

否则:

Toast.makeText(getApplication(), sendlist.size().toString()+"", Toast.LENGTH_LONG).show();

bcoz 它将允许字符串中的第二个参数..并且还使用 getApplication 而不是这个例子:

Toast.makeText(getApplicationContext(),
"Error during request: " + e.getLocalizedMessage(),
Toast.LENGTH_LONG).show();

谢谢,,

关于java - .资源$NotFoundException : String resource ID #0x3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22602457/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com