我正在开发一个将图片发送到 url 的应用程序。目前,一旦我将我的应用程序发送到 MailSenderActivity java 类,我就会遇到问题。每次运行它时,我都会收到一条错误消息,提示我有资源未找到异常。我试图通过有根据的猜测和注释掉部分来在我的代码中找到此错误的来源,但我无法找到错误的来源或解决方案。非常欢迎任何帮助。我已经添加了我的 LogCat、java 类和我的清单。
MailSenderActivity 类
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.Toast;
import android.widget.EditText;
import android.telephony.TelephonyManager;
public class MailSenderActivity extends Activity implements OnClickListener {
public String subj;
public String body;
public String from;
public String toList;
public String ptName;
public String ptDesc;
public String ptType;
public String ptURL;
private String ptURL_noFTP;
private String ptLat;
private String ptLng;
private String item_sep;
private Context c;
private Button send;
private Button button_return;
private MailSenderActivity self = this;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
c = super.getApplicationContext();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
body = "Body.";
/*ptLat = Globals.lat;
ptLng = Globals.lng;
final LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
final LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
(long) 2000, (float) 1.0, mlocListener); // (provider,*/
// time
// (ms),
// distance
// (m),
// listener)
Intent thisIntent = getIntent();
ptType = thisIntent.getStringExtra("Type");
ptURL = "urlIsHere"
+ thisIntent.getStringExtra("Filename");
ptURL_noFTP = "urlIsHere"
+ thisIntent.getStringExtra("Filename");
ptName = thisIntent.getStringExtra("Filename");
setContentView(R.layout.mail_prep_apv);
setLayout(ptType);
send = (Button) findViewById(R.id.Send);
send.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case (R.id.Send):
InputMethodManager inputManager = (InputMethodManager) c
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus()
.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
from = "email";
toList = "email";
EditText etName = (EditText) findViewById(R.id.pointName);
ptName = etName.getText().toString();
EditText etDesc = (EditText) findViewById(R.id.pointDesc);
ptDesc = etDesc.getText().toString();
item_sep = getResources().getString(R.string.item_separator);
subj = "POINT: " + ptName + item_sep + /*ptLat +*/ item_sep /*+ ptLng*/
+ item_sep + ptType + item_sep + ptDesc;
new MyAsyncTask(this).execute();
setContentView(R.layout.sent);
button_return = (Button) findViewById(R.id.Return);
button_return.setOnClickListener(self);
break;
case (R.id.Return):
send.setClickable(true);
finish();
break;
}
}
public void setLayout(String type) {
if (type.equals(getResources().getString(R.string.type_comment)))
setContentView(R.layout.mail_prep_comment);
else if (type.equals(getResources().getString(R.string.type_android))) {
setContentView(R.layout.mail_prep_android);
/*EditText pointName = (EditText) findViewById(R.id.pointName);
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
pointName.setText(telephonyManager.getDeviceId());*/
} else if (type.equals(getResources().getString(R.string.type_audio))
|| type.equals(getResources().getString(R.string.type_picture))
|| type.equals(getResources().getString(R.string.type_video))) {
setContentView(R.layout.mail_prep_apv);
EditText pointDesc = (EditText) findViewById(R.id.pointDesc);
pointDesc.setText(ptURL_noFTP);
EditText pointName = (EditText) findViewById(R.id.pointName);
pointName.setText(ptName);
}
}
/*private class MyLocationListener implements LocationListener {
public void onLocationChanged(Location loc) {
Toast.makeText(c, "Getting Location.", Toast.LENGTH_SHORT).show();
ptLat = "" + loc.getLatitude();
ptLng = "" + loc.getLongitude();
}
public void onProviderDisabled(String provider) {
Toast.makeText(c, "GPS Disabled", Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider) {
Toast.makeText(c, "GPS Enabled", Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}*/
public void onBackPressed() {
setResult(Activity.RESULT_CANCELED, null);
finish();
}
private class MyAsyncTask extends AsyncTask<Integer, String, Boolean> {
private Context context;
public MyAsyncTask(Context context) {
this.context = context;
}
protected Boolean doInBackground(Integer... params) {
try {
GMailSender sender = new GMailSender(
"urlIsHere", "EmbraceChaos");
sender.sendMail(subj, body, from, toList);
} catch (Exception e) {
System.out.println("EXCEPTION: " + e);
setContentView(R.layout.send_failed);
}
return true;
}
protected void onPostExecute(Boolean result) {
Toast.makeText(context,
"Latest media was uploaded to Virtual Command Center.",
Toast.LENGTH_LONG).show();
}
}
}
日志猫
10-06 14:05:19.131: E/AndroidRuntime(5576): FATAL EXCEPTION: main
10-06 14:05:19.131: E/AndroidRuntime(5576): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cameratest/com.cameratest.MailSenderActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030003
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.os.Looper.loop(Looper.java:137)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-06 14:05:19.131: E/AndroidRuntime(5576): at java.lang.reflect.Method.invokeNative(Native Method)
10-06 14:05:19.131: E/AndroidRuntime(5576): at java.lang.reflect.Method.invoke(Method.java:511)
10-06 14:05:19.131: E/AndroidRuntime(5576): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-06 14:05:19.131: E/AndroidRuntime(5576): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-06 14:05:19.131: E/AndroidRuntime(5576): at dalvik.system.NativeStart.main(Native Method)
10-06 14:05:19.131: E/AndroidRuntime(5576): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030003
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.content.res.Resources.getValue(Resources.java:1013)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2098)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.content.res.Resources.getLayout(Resources.java:852)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-06 14:05:19.131: E/AndroidRuntime(5576): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.app.Activity.setContentView(Activity.java:1867)
10-06 14:05:19.131: E/AndroidRuntime(5576): at com.cameratest.MailSenderActivity.onCreate(MailSenderActivity.java:65)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.app.Activity.performCreate(Activity.java:5008)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-06 14:05:19.131: E/AndroidRuntime(5576): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-06 14:05:19.131: E/AndroidRuntime(5576): ... 11 more
显现
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cameratest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Main"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="sate2012.avatar.android.UploadMedia"
android:label="@string/app_name"
android:screenOrientation="landscape" >
</activity>
<activity
android:name="sate2012.avatar.android.MailSenderActivity"
android:label="Upload Data Point" >
<intent-filter>
<action android:name="android.intent.action.MAILSENDERACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="sate2012.avatar.android.GMailSender"
android:label="@string/title_mail_sender_activity"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="sate2012.avatar.android.GMAILSENDER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="sate2012.avatar.android.UploadData"
android:label="UploadData" >
<intent-filter>
<action android:name="sate2012.avatar.android.UPLOADDATA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".UploadMedia"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.UPLOAD_MEDIA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Photographer"
android:label="photoclass" >
<intent-filter>
<action android:name="android.intent.action.PHOTOGRAPHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".UploadFTP"
android:label="photoclass" >
<intent-filter>
<action android:name="android.intent.action.UPLOAD_FTP" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MailSenderActivity"
android:label="photoclass" >
<intent-filter>
<action android:name="android.intent.action.MAILSENDERACTIVITY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>