0

写真を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();
        }
    }
}

LogCat

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>
4

1 に答える 1

0

問題を解決したところ、ソースが行方不明の xml ファイルへの誤った参照であることがわかりました。修正したところ、エラーは発生しなくなりました。

于 2012-10-06T19:55:17.203 に答える