I am using OpenCSV in an Android Java project with IntelliJ.
I am trying to run the following code to create a bean inside my project. Note the segment surrounded by "** **"
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import com.opencsv.bean.CsvToBeanBuilder;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity implements View.OnClickListener
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_page);
**List<Restrictions> restrictionData = new CsvToBeanBuilder(FileReader("restrictions.csv"))
.withType(Restrictions.class).build.parse();**
}
}
I have taken this code from OpenCSV's site where they say:
Here we simply name the fields identically to the header names. After
that, reading is a simple job:
List beans = new CsvToBeanBuilder(FileReader("yourfile.csv"))
.withType(Visitors.class).build().parse();
This will give you a list of the two beans as defined in the example input file. Note how type conversions to basic data types (wrapped and unwrapped primitives, enumerations, and Strings) occur automatically.
My code resembles their same style. Here is the error I get:
C:\Programming\Android\GoTimeJavaVersion\app\src\main\java\com\example\gotimejavaversion\MainActivity.java:34: error: cannot find symbol
List<Restrictions> restrictionData = new CsvToBeanBuilder(FileReader("restrictions.csv"))
^
symbol: method FileReader(String)
location: class MainActivity
I have tried putting 'new' in front of FileReader, and when I do this I get THIS error:
C:\Programming\Android\GoTimeJavaVersion\app\src\main\java\com\example\gotimejavaversion\MainActivity.java:35: error: cannot find symbol
.withType(Restrictions.class).build.parse();
^
symbol: variable build
location: class CsvToBeanBuilder
I have OpenCSV and beanutils in my library, both implemented in my build.gradle, and my file restrictions.csv is in my app's src folder. My Restrictions class also has no errors and follows OpenCSV's bean setup to a tee.
What am I doing wrong? Any help appreciated, thank you!
Use any of the below constructors for CsvToBeanBuilder. Constructor you are using is not valid :-
CsvToBeanBuilder(CSVReader csvReader)
CsvToBeanBuilder(Reader reader)
example :-
CSVReader csvReader = new CSVReader(new FileReader("restrictions.csv"));
List<Restrictions> restrictionData = new CsvToBeanBuilder(csvReader)
.withType(Restrictions.class)
.build()
.parse();
Related
I'm coding a Minecraft mod and ran into an error when trying to start Ore Generation. The error is on the word "register" and the only action is Rename Reference. Here is my code.
package com.monkeyminers.mod1.world.feature;
import net.minecraft.core.Holder;
import net.minecraft.data.worldgen.placement.PlacementUtils;
import net.minecraft.world.level.levelgen.VerticalAnchor;
import net.minecraft.world.level.levelgen.placement.HeightRangePlacement;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
public class ModPlacedFeatures {
public static final Holder<PlacedFeature> CITRINE_ORE_PLACED =
PlacementUtils.register("graphene_ore_placed",
ModConfiguredFeatures.GRAPHENE_ORE, ModOrePlacement.commonOrePlacement(1, //
VeinsPerChunk
HeightRangePlacement.triangle(VerticalAnchor.aboveBottom(-80),
VerticalAnchor.aboveBottom(80))));
}
I tried to update my dynamodb using aws but I am not able to create a dynamodb object or a table object as the import com.amazonaws.services.dynamodbv2.**document**.* does not register document but it reads all the other imports:
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.ListTablesResult;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.TableDescription;
Below is the full class I am using:
import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.model.UpdateItemRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec;
import com.amazonaws.services.dynamodbv2.document.utils.ValueMap;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.document.TableCollection;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec;
import com.amazonaws.services.dynamodbv2.document.utils.ValueMap;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.document.TableCollection;
import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.dynamodbv2.model.KeyType;
import com.amazonaws.services.dynamodbv2.model.ListTablesResult;
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput;
import com.amazonaws.services.dynamodbv2.model.TableDescription;
public class LoadingPage extends AppCompatActivity {
static AmazonDynamoDBClient dynamoDB;
LocationManager locationmanager;
private TrackGPS gps;
double longitude;
double latitude;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loading_page);
gps = new TrackGPS(LoadingPage.this);
DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient(
new ProfileCredentialsProvider()));
Table table = dynamoDB.getTable("ProductCatalog");
Map<String, String> expressionAttributeNames = new HashMap<String, String>();
expressionAttributeNames.put("#A", "Authors");
expressionAttributeNames.put("#P", "Price");
expressionAttributeNames.put("#I", "ISBN");
Map<String, Object> expressionAttributeValues = new HashMap<String, Object>();
expressionAttributeValues.put(":val1",
new HashSet<String>(Arrays.asList("Author YY","Author ZZ")));
expressionAttributeValues.put(":val2", 1); //Price
UpdateItemOutcome outcome = table.updateItem(
"Id", // key attribute name
101, // key attribute value
"add #A :val1 set #P = #P - :val2 remove #I",
expressionAttributeNames,
expressionAttributeValues);
I had a similar problem and what I've learned is that the availability of, and/or source repositories for, packages can change over time.Therefore, if an import cannot be resolved, the following procedure may help.
Identify the package that supplies the dependency.
Locate a source for the package.
Configure the source with Gradle or Maven.
For my answer, I verified your desired imports against com.amazonaws:DynamoDBLocal:1.11.477 under Kotlin.
From the artifact page at MVNRepository, I selected View All.
This led me to a repository source with the following URL:
https://repository.mulesoft.org/nexus/content/repositories/public/com/amazonaws/DynamoDBLocal/1.11.477/
Since I was using Kotlin, I added the corresponding repository data to repositories in my build.gradle.kts for Gradle.
// Local DynamoDB.
repositories {
maven(url = "https://repository.mulesoft.org/nexus/content/repositories/public")
}
dependencies {
implementation ("com.amazonaws:DynamoDBLocal:1.11.477")
}
These imports, for the non-local case, can also be satisfied from the package at:
http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-dynamodb/1.11.564/
Therefore, the following entries also work:
// Remote DynamoDB.
repositories {
mavenCentral()
}
dependencies {
implementation("com.amazonaws:aws-java-sdk-dynamodb:1.11.564")
}
After configuring my project for either the local or remote versions, I was able to verify that all of your imports that include "document" were available.
I'm assuming you probably tried this already, but it worked for me so I'm going to mention it anyway: I made sure that the AWS SDK for Java library had been added and then I refreshed the project. Now all is working!
I closed my project down and reopened it many times with no success, but refreshing the project did the trick. Good luck.
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.
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.
Following is MainActivity code. This code is written to calculate nearest located Latlong distance..
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..
Removed import android.R; And clean and rebuild your project
import your_application_package_name.R;
Error 1 indicates that the build system cannot find a layout file called "activity_main.xml". Verify that you have such a layout file.
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.:
List<YourTypeHere> csvFile2List = null;
Delete import.android.R; and in place of it, add import com.example.latlong.R; if com.example.latlong is your package name.
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.
I am trying to create a code which will convert images into video. I have surfed a lot and find some method to do it using javacv. now i am getting variable not found error in these lines.
recorder.setCodecID( CODEC_ID_MPEG1VIDEO);
recorder.setPixelFormat( PIX_FMT_YUV420P);
I have imported all the jar files into my library as well but still getting this error. Some quick help would be appreciated. I have gone through the below link for the importing the javacv into my workspace.
How to Import JavaCV libraries to Android Project
package com.example.photoaday;
import static com.googlecode.javacv.cpp.opencv_core.cvReleaseImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvShowImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvWaitKey;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_GAUSSIAN;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvSmooth;
import com.googlecode.javacv.FFmpegFrameRecorder;
import com.googlecode.javacv.cpp.opencv_core;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class Recordvideo extends Activity {
// #Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create);
opencv_core.IplImage img = cvLoadImage("/sdcard/folder/img1.jpg");
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("/sdcard/folder/test.mpeg",200,150);
try {
recorder.setCodecID( CODEC_ID_MPEG1VIDEO);
recorder.setFrameRate(30);
recorder.setPixelFormat( PIX_FMT_YUV420P);
recorder.start();
for (int i=0;i<100;i++)
{
recorder.record(img);
}
recorder.stop();
}
catch (Exception e){
e.printStackTrace();
}
}
}
I assume that your compiler gives error as follows
error: ‘CODEC_ID_MPEG1VIDEO’ was not declared in this scope
error: ‘PIX_FMT_YUV420P’ was not declared in this scope
then solution for error is
change : ‘CODEC_ID_MPEG1VIDEO’ to 'AV_CODEC_ID_MPEG1VIDEO'
change : ‘PIX_FMT_YUV420P’ to 'AV_PIX_FMT_YUV420P'
I am using xuggler to play video files from my code and the following is a snippet from the main code:
This snippet produces an error :
//The window we'll draw the video on.
private static VideoImage mScreen = null;
private static void updateJavaWindow(BufferedImage javaImage)
{
mScreen.setImage(javaImage);
}
// Opens a Swing window on screen.
private static void openJavaWindow()
{
mScreen = new VideoImage();
}
The error that i get is : cannot find symbol : class VideoImage
The header files used are :
import java.awt.image.BufferedImage;
import com.xuggle.xuggler.Global;
import com.xuggle.xuggler.IContainer;
import com.xuggle.xuggler.IPacket;
import com.xuggle.xuggler.IPixelFormat;
import com.xuggle.xuggler.IStream;
import com.xuggle.xuggler.IStreamCoder;
import com.xuggle.xuggler.ICodec;
import com.xuggle.xuggler.IVideoPicture;
import com.xuggle.xuggler.IVideoResampler;
import com.xuggle.xuggler.Utils;
Am i missing in some import statement ? If not , here are the libraries i am using apart from JDK :
What is the reason i am getting that error ?
VideoImage Javadoc
You are not importing the right class.
com.xuggle.xuggler.demos.VideoImage
It seems like you are already using an IDE. It should automatically tell you what import you are missing if the correct library is in the build path.
You need to import the VideoImage class.