java - 我的应用程序无法编译,当它抛出错误时,我所有的资源文件都消失了

标签 java android xml android-fragments build.gradle

出于某种原因,每当我尝试编译我的 android studio 项目时,它总是说我的图像“默认”无效。它没有任何意义,因为在 XML 文件中,当您将 View 更改为 View 的设计模式时,它没有显示问题。在我编译之后,Gradle 抛出了一个问题和我所有的“R”。变成找不到符号。即无论何时我喜欢 R.id.textview,我所有的 R 都会变成红色并且我无法将其改回。

我的错误:

Error:error: invalid symbol: 'default'
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Studio.app/sdk/build-tools/android-4.4W/aapt package -f --no-crunch -I /Applications/Android Studio.app/sdk/platforms/android-20/android.jar -M /Users/Anuraag/AndroidStudioProjects/Weather/app/build/intermediates/manifests/debug/AndroidManifest.xml -S /Users/Anuraag/AndroidStudioProjects/Weather/app/build/intermediates/res/debug -A /Users/Anuraag/AndroidStudioProjects/Weather/app/build/intermediates/assets/debug -m -J /Users/Anuraag/AndroidStudioProjects/Weather/app/build/generated/source/r/debug -F /Users/Anuraag/AndroidStudioProjects/Weather/app/build/intermediates/libs/app-debug.ap_ --debug-mode --custom-package com.anuraagy.weather -0 apk
  Error Code:
    1
  Output:
    res/drawable-hdpi-v4/default.png:0: error: invalid symbol: 'default'

主要 Activity

package com.anuraagy.weather;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.ByteArrayOutputStream;
import java.io.IOException;


public class MyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);
        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_my, container, false);



            RequestTask task = new RequestTask();
            task.execute(new String[]{"http://stackoverflow.com"});

            return rootView;
        }
    }
    public static class RequestTask extends AsyncTask<String, String, String> {

        @Override
        protected String doInBackground(String... uri) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response;
            String responseString = null;
            try {
                response = httpclient.execute(new HttpGet(uri[0]));
                StatusLine statusLine = response.getStatusLine();
                if(statusLine.getStatusCode() == HttpStatus.SC_OK){
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    response.getEntity().writeTo(out);
                    out.close();
                    responseString = out.toString();
                } else{
                    //Closes the connection.
                    response.getEntity().getContent().close();
                    throw new IOException(statusLine.getReasonPhrase());
                }
            } catch (ClientProtocolException e) {
                //TODO Handle problems..
            } catch (IOException e) {
                //TODO Handle problems..
            }

            Log.i("",responseString);
            return responseString;
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            //Do anything with response..
        }
    }
}

我的 XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MyActivity$PlaceholderFragment">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/default"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />


    <!--<TextView-->
        <!--android:layout_width="wrap_content"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:textAppearance="?android:attr/textAppearanceLarge"-->
        <!--android:text="80&#xb0;F"-->
        <!--android:id="@+id/textView2"-->
        <!--android:textSize="90sp"-->
        <!--android:layout_alignTop="@+id/imageView"-->
        <!--android:layout_alignRight="@+id/textView3"-->
        <!--android:layout_alignEnd="@+id/textView3" />-->

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="It's definitely sunny. now."
        android:textStyle="bold"
        android:id="@+id/textView3"
        android:textSize="70sp"
        android:layout_above="@+id/textView4"
        android:layout_alignLeft="@+id/textView4"
        android:layout_alignStart="@+id/textView4" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Stop being lazy and just look outside bruh >.>"
        android:textSize="14sp"
        android:textColor="#7f8c8d"
        android:id="@+id/textView4"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />


</RelativeLayout>

最佳答案

已修复,问题是我按图像默认命名,这在 android 中是不允许的。这会搞砸我的资源类。

关于java - 我的应用程序无法编译,当它抛出错误时,我所有的资源文件都消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26237095/

相关文章:

java - 用于部署 Java "Side By Side"和工具的 Linux 标准?

java - 通过前缀获取 application.properties 的子集

android - Flutter - 将 lib Flutter 添加到 Android 项目

java - 为什么我得到 result.get(CaptureResult.CONTROL_AF_STATE); == 无效?

java - 如何在 EditText 密码输入字段旁边放置 ImageView

Python UTF-8 XML 解析 (SUDS) : Removing 'invalid token'

python - HDI : write large string xml into file (python xml. dom.minidom)

java - 为什么字符串在许多编程语言中都是不可变的?

java - 错误地合并排序输出

android - 获取 SQLite 数据库并将其存储在对象数组中