【问题标题】:R cannot be resolved (Another)R无法解决(另一个)
【发布时间】:2013-05-23 15:42:36
【问题描述】:

嗯 - 在过去的几天里,我已经阅读了几乎所有关于这个主题的威胁,但没有一个奏效!

我刚刚开始开发一个新的应用程序,一旦创建项目,就会出现错误。

作为最后的手段,可以请一些人(或 gal :))观察一下,看看他们是否能发现可能阻碍我的应用程序功能的问题?

MainApplication.java;

 package com.sony.thirdtest;

import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.view.View;
import android.widget.Toast;
import com.sony.smallapp.SmallAppWindow;
import com.sony.smallapp.SmallApplication;

public class MainApplication extends SmallApplication {
private Configuration mConfig;

@Override
public void onCreate() {
    super.onCreate();
    mConfig = new Configuration(getResources().getConfiguration());

    setContentView(R.layout.activity_main);
    setTitle(R.string.app_name);

    SmallAppWindow.Attributes attr = getWindow().getAttributes();
    attr.minWidth = 200;
    attr.minHeight = 200;
    attr.width = 400;
    attr.height = 300;
    attr.flags |= SmallAppWindow.Attributes.FLAG_RESIZABLE;
    getWindow().setAttributes(attr);

    findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(MainApplication.this, R.string.hello, Toast.LENGTH_SHORT).show();
        }
    });
}

@Override
public void onDestroy() {
    super.onDestroy();
}

@Override
public void onStart() {
    super.onStart();
}

@Override
public void onStop() {
    super.onStop();
}

@Override
protected boolean onSmallAppConfigurationChanged(Configuration newConfig) {
    int diff = newConfig.diff(mConfig);
    mConfig = new Configuration(getResources().getConfiguration());
    // Avoid application from restarting when orientation changed
    if ((diff & ActivityInfo.CONFIG_ORIENTATION) != 0) {
        return true;
    }
    return super.onSmallAppConfigurationChanged(newConfig);
}

}

main_activity.xml;

<manifest  
package="com.sony.thirdtest" 
android:versionCode="1" 
android:versionName="1.0"
xmlns:android="http://schemas.android.com/apk/res/android" >

<uses-sdk android:minSdkVersion="14"
          android:targetSdkVersion="15" />

<uses-permission android:name="com.sony.smallapp.permission.SMALLAPP" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >   


    <uses-library android:name="com.sony.smallapp.framework" />

    <service 
        android:name="MainApplication"

        android:exported="true" >

        <intent-filter >

            <action android:name="com.sony.smallapp.intent.action.MAIN" />

            <category android:name="com.sony.smallapp.intent.category.LAUNCHER" />

        </intent-filter>

    </service>

</application>

我能否明确说明这是最后的手段,

亲切的问候。

【问题讨论】:

  • 您的资源文件中是否有任何错误。交叉检查一次?将 adt 更新到 rev 22 后是否发生这种情况?
  • 我正在运行最新版本的 ADT,所以我会这么认为。我在资源文件夹中的唯一文件是 ic_launcher.png - 在可绘制文件夹中。程序中没有其他错误。就这两个关于“R”
  • stackoverflow.com/questions/16636039/…。尝试这个。如果它崩溃了,我建议你发布崩溃的 logcat 信息
  • //缺少一个。另外你确定你想要一个服务而不是活动吗?developer.android.com/guide/components/services.html
  • 导入 com.sony.thirdtest.R;

标签: android resolve sony


【解决方案1】:

这是可能的错误。 findViewById(R.id.button).setOnClickListener(new View.OnClickListener()

以这种方式声明按钮并尝试

            public class MainApplication extends SmallApplication {
             private Configuration mConfig;
             Button button1;

                  @Override
                 public void onCreate() {
                button1 = (Button) findViewById(R.id.button1);
                  button1.setOnClickListener(new OnClickListener()
                      {
                         Toast.makeText(getBaseContext(), 
                    "your message", 
                    Toast.LENGTH_SHORT).show();
                    }
                 }

【讨论】:

    【解决方案2】:

    它在最终文件中缺少清单应答器。最好先放 xmlns 属性。试试这个:

    <manifest  
        xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.sony.thirdtest" 
        android:versionCode="1" 
        android:versionName="1.0"
         >
    
        <uses-sdk android:minSdkVersion="14"
                  android:targetSdkVersion="15" />
    
        <uses-permission android:name="com.sony.smallapp.permission.SMALLAPP" />
    
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >   
    
    
            <uses-library android:name="com.sony.smallapp.framework" />
    
            <service 
                android:name="MainApplication"
    
                android:exported="true" >
    
                <intent-filter >
    
                    <action android:name="com.sony.smallapp.intent.action.MAIN" />
    
                    <category android:name="com.sony.smallapp.intent.category.LAUNCHER" />
    
                </intent-filter>
    
            </service>
    
        </application>
        </manifest>
    

    【讨论】:

      【解决方案3】:

      已经很晚了,但我多次遇到这个问题,我想分享我的意见。问题在于您的资源文件。检查您的布局、值等。广告总是会说import android.Rimport com.yourpackage.R。不要认为快速修复。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-14
        • 2021-07-24
        • 1970-01-01
        • 2014-06-22
        • 2011-09-11
        • 2013-02-15
        • 1970-01-01
        • 2018-04-25
        相关资源
        最近更新 更多