本文介绍了Android的编程错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结果
我做了Android的Hello,测试教程使用Eclipse的伽利略。 ()当我尝试编译并运行程序,我得到一个错误说com.example.helloandroid.R.id解决不了。


I am doing the Android "Hello, Testing" Tutorial using Eclipse Galileo. (http://developer.android.com/resources/tutorials/testing/helloandroid_test.html) When I try to compile and run the program I get an error saying "com.example.helloandroid.R.id cannot be resolved".

package com.example.helloandroid.test;  
import com.example.helloandroid.HelloAndroid;  
import android.test.ActivityInstrumentationTestCase2;  
import android.widget.TextView;

public class HelloAndroidTest extends ActivityInstrumentationTestCase2<HelloAndroid>  
{    
    private HelloAndroid mActivity;  // the activity under test    
    private TextView mView;          // the activity's TextView (the only view)    
    private String resourceString;    

    public HelloAndroidTest() 
    {      
        super("com.example.helloandroid", HelloAndroid.class);    
    }    

    @Override    
    protected void setUp() throws Exception 
    {        
        super.setUp();        
        mActivity = this.getActivity();        
        mView = (TextView) mActivity.findViewById(com.example.helloandroid.R.id.textview);        
        resourceString = mActivity.getString(com.example.helloandroid.R.string.hello);    
    }    

    public void testPreconditions() 
    {      
        assertNotNull(mView);    
    }    

    public void testText() 
    {      
        assertEquals(resourceString,(String)mView.getText());    
    }
}  

感谢您的帮助/提醒您可以提供!

Thanks for any help/advise you can offer!

推荐答案

这种事情,似乎即使没有做错任何事,有时随机发生的,所以先尝试清洁您的项目,迫使一个完整的重建和R.java的再生。

This kind of thing seems to randomly happen sometimes even without anything done wrong, so first try cleaning your project to force a complete rebuild and regeneration of R.java.

如果不解决这个问题,你可能要重新开始,并非常肯定你遵循项目设置完全说明。您明确提及com.example.helloandroid.R需要您的项目被命名的,而不是com.example.HelloAndroidTest,因为它最终可能,如果这是你的主类。如果你打开​​了根/文件夹,看到一个.R.java不是在com.example.helloandroid包是你的问题 - 产生的R舱的包装,您需要引用它的绝对或相对的名字相匹配。

If that doesn't fix it, you may want to start over and be very sure you follow the instructions for project setup exactly. Your explicit reference to com.example.helloandroid.R requires that your project be named that, and not com.example.HelloAndroidTest as it might end up if that's your main class. If you open up the gen/ folder and see an .R.java that isn't in the com.example.helloandroid package that's your problem - the package of the generated R class and the absolute or relative name you refer to it by need to match.

这篇关于Android的编程错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 05:34