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

Posted

技术标签:

【中文标题】我的应用程序无法编译,当它引发错误时,我的所有资源文件都消失了【英文标题】:My App wont compile and when it throws an error all my resource files are gone 【发布时间】:2014-12-01 22:39:52 【问题描述】:

由于某种原因,当我尝试编译我的 android studio 项目时,它一直说我的图像“默认”无效。这没有任何意义,因为在 XML 文件中,当您将视图更改为视图的设计模式时,显示没有问题。编译后,Gradle 会抛出一个问题和我所有的“R”。变成 Symbol not found。即,无论我喜欢 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'

主要活动

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://***.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_
    android:layout_
    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_
        android:layout_
        android:id="@+id/imageView"
        android:src="@drawable/default"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />


    <!--<TextView-->
        <!--android:layout_-->
        <!--android:layout_-->
        <!--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_
        android:layout_
        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_
        android:layout_
        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>

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于我的应用程序无法编译,当它引发错误时,我的所有资源文件都消失了的主要内容,如果未能解决你的问题,请参考以下文章

双向链表 - 是啥导致我的代码引发编译器错误,我该如何解决?

当我将WPF UserControl用于其内置项目以外的项目时,我的WPF UserControl无法找到资源

所有 apollo 查询错误都会引发网络 400 错误

在play框架中,无法编译文件XX.java。引发的错误是:无法在 Eclipse 中解析导入 XXX

为啥 AVR-GCC 编译器在使用相同的变量但作为 PROGMEM 重载时会引发错误?

Webpack 不加载“资产/资源”类型