错误: - 活动主要无法解析或不是一个字段

时间:2022-06-07 03:29:10

I searched this error and tried all available solutions but still getting this error. I am new to android so please help to rectify and remove this error. I am fully aware that this error is somewhat associated with .R file of android.

我搜索了这个错误并尝试了所有可用的解决方案但仍然收到此错误。我是android的新手,所以请帮助纠正并删除此错误。我完全清楚这个错误与android的.R文件有些关联。

I am using eclipse and getting 2 error 1- "activity_main cannot be resolved or is not a field" 2- List is a raw type. Reference to generic type.

我正在使用eclipse并获得2个错误1-“activity_main无法解析或不是字段”2-列表是原始类型。参考泛型类型。

Following is MainActivity code. This code is written to calculate nearest located Latlong distance..

以下是MainActivity代码。编写此代码是为了计算最近的Latlong距离..

package com.example.latlong;

  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.util.List;
  import android.R;

  import android.app.Activity;
  import android.location.Location;
  import android.os.Bundle;
  import android.os.Environment;

  import com.opencsv.CSVReader;
  import com.opencsv.CSVWriter;

  public class MainActivity extends Activity {

    Double latToCompare=0.0, longToCompare=0.0;
    float shortestDistance = 0.0f;
    Boolean isDistanceComparedFirstTime = true;
    Boolean isFirstRowInCSV1 = true, isFirstRowInCSV2 = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);  /////// Error1 Line


        createDirIfNotExists("/windows/Pictures/LatLongFiles");

        String csvFilename1 =     Environment.getExternalStorageDirectory()+"/windows/Pictures/LatLongFiles/Data.csv";
        String csvFilename2 = Environment.getExternalStorageDirectory()+"/windows/Pictures/LatLongFiles/SourceFile.csv";
        String csvFilename3 = Environment.getExternalStorageDirectory()+"/windows/Pictures/LatLongFiles/OutputFile.csv";

        CSVReader csvReader1 = null;
        CSVReader csvReader2 = null;
        CSVWriter csvWriter3 = null;    

        List csvFile2List = null;     /////////////   Error2  Line

I know this error is not new to you android guys but i tried everything and still stuck on this error.. Thanks in advance..

我知道这个错误对你来说并不是什么新东西,但我尝试了一切,仍然坚持这个错误..在此先感谢..

3 个解决方案

#1


2  

Removed import android.R; And clean and rebuild your project

删除了导入android.R;并清理和重建您的项目

import your_application_package_name.R;

#2


0  

Error 1 indicates that the build system cannot find a layout file called "activity_main.xml". Verify that you have such a layout file.

错误1表示构建系统找不到名为“activity_main.xml”的布局文件。验证您是否有这样的布局文件。

Error 2 is simply a warning that informs you that you are using a raw type rather than a generic type. Add a type parameter that indicates the type of objects that are to reside in your list, e.g.:

错误2只是一个警告,通知您使用的是原始类型而不是泛型类型。添加一个类型参数,指示要驻留在列表中的对象的类型,例如:

List<YourTypeHere> csvFile2List = null;

#3


0  

Delete import.android.R; and in place of it, add import com.example.latlong.R; if com.example.latlong is your package name.

删除import.android.R;并代替它,添加import com.example.latlong.R;如果com.example.latlong是您的包名称。

Or if this is not your package name, see your manifest file for the package name. And add import YourPackageName.R; instead of import.android.R; where YourPackageName is the name of your package.

或者,如果这不是您的包名称,请参阅清单文件以获取包名称。并添加import YourPackageName.R;而不是import.android.R;其中YourPackageName是包的名称。

#1


2  

Removed import android.R; And clean and rebuild your project

删除了导入android.R;并清理和重建您的项目

import your_application_package_name.R;

#2


0  

Error 1 indicates that the build system cannot find a layout file called "activity_main.xml". Verify that you have such a layout file.

错误1表示构建系统找不到名为“activity_main.xml”的布局文件。验证您是否有这样的布局文件。

Error 2 is simply a warning that informs you that you are using a raw type rather than a generic type. Add a type parameter that indicates the type of objects that are to reside in your list, e.g.:

错误2只是一个警告,通知您使用的是原始类型而不是泛型类型。添加一个类型参数,指示要驻留在列表中的对象的类型,例如:

List<YourTypeHere> csvFile2List = null;

#3


0  

Delete import.android.R; and in place of it, add import com.example.latlong.R; if com.example.latlong is your package name.

删除import.android.R;并代替它,添加import com.example.latlong.R;如果com.example.latlong是您的包名称。

Or if this is not your package name, see your manifest file for the package name. And add import YourPackageName.R; instead of import.android.R; where YourPackageName is the name of your package.

或者,如果这不是您的包名称,请参阅清单文件以获取包名称。并添加import YourPackageName.R;而不是import.android.R;其中YourPackageName是包的名称。