"Cannot resolve R" everywhere after converting module from application to feature - java

I am trying to add instant app functionality to my project. So I am following the instructions given in this tutorial : https://codelabs.developers.google.com/codelabs/android-instant-apps/#0
The fifth chapter explains how to move the existing code from an application module to a feature module. I'm following this tutorial step-by-step, updating both the playground topeka project given with this tutorial and my project. However, I'm stuck after the first sub-chapter "Convert the app module into a feature module called topeka-base".
After renaming my project folder to project-base, and transforming it from com.android.application to com.android.feature, the Gradle sync runs fine but I can't rebuild my project anymore, since every occurrence of my.project.R get a Cannot resolve symbol 'R' error. I'm not having this problem with the topeka app that comes along with the tutorial, however.
As you can see below, there is no such error in topeka project:
So I tried looking at my project generated files to find a difference, but actually I don't see any difference with topeka:
package my.project;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "my.project";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 38;
public static final String VERSION_NAME = "1.9.0";
}
So what could be the reason? Thanks for your help.

You can first start with trying to clean and then rebuild the project sometimes it fixes the issue.
You can also try invalidating the caches and restarting the android studio.
Also, I guess you should check the manifest file and edit the app's name there.

Related

NoClassDefFoundError when trying to pass an object from a project to an API Rest

I have a problem with one of my project. Here is a little more info about it :
Our teacher gave us a virtual machine (ubuntu) which contains Hadoop and Hbase, already setup.
The objective is pretty simple : we have a Rest api with tomcat 8.5 (RestServer project, web project), which intercept GET requests (our teacher only want us to have GET request, security reason apparently), and we need to perform, according to the url (for instance : /students/{id}/{program} will return the grades summary for this particular student (id) and year of study (program)), data selection and mapreduce job on Hbase tables. And we have a BigData project, which contains simple java code to scan and filter Hbase table. Here is the short summary of the project.
Here is the structure we use for this project : project structure
And here is what is the execution logic : we type our url in the browser, after we launched our RestServer project (right click on RestServer -> Run as -> Run on server.
Here is what we get after doing so : RestServer in the browser.
The easy part stop there. The links we see on the previous image are just for demo, they are not what we need to do in this project. The idea is to intercept the GET request from the api, in the method handling the request, get the parameters, give them to a call to the constructor of our response object, and return the object as the response (that will be transform into a JSON). The idea is to get this object (the response to our GET request) from the BigData project. So we need to make this 2 projects communicate.
Here is the code to intercept the request :
#GET
#Path("/students/{id}/{program}")
#Produces(MediaType.APPLICATION_JSON)
public Response getStudent(#PathParam("id") String ID,#PathParam("program") String program) throws IOException {
System.out.println("ID : "+ID+" program"+program);
if (ID != null) {
System.out.println("Non nul");
return Response.ok(new Response1(ID,program), MediaType.APPLICATION_JSON).build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity("Student not found: " + ID).build();
}
}
The Response1(ID,program) object is build in the BigData project. When i execute the code from the BigData project directly (as Java application), i have absolutely no problem, no error. But the idea is to use the code from the BigData project to build the Result1 object, and "give it back" to the Rest api. The problem is here, i tried absolutely everything i know and found on the internet but i can't resolve this problem. When i type my url, (which is : http://localhost:8080/RestServer/v1/StudentService/students/2005000033/L3) i get this error : error
From my research, i found that (correct me if i'm wrong) the program can't find the ByteArrayComparable class at runtime. I looked all the links i could find, and here is what i tried to resolve it :
Check if the library for Hadoop and Hbase are in both projects.
Check if the projects contains hbase-client, which is suppose to contains the ByteArrayComparable class (yes, it is in both projects).
By doing right click on RestServer -> Properties -> Java Build Path :
Source tab : i added the src folder from BigData project (and bin folder, but i can't remember where, i believe it is in one of the tab of Java Build Path).
Projects tab : i added the BigData project.
Order and Export tab : i checked the src folder (this folder is in the RestServer project, created after i added the src folder from BigData project in the Source tab).
Deployement Assembly : i added BigData project.
I copied the class which are use in the BigData project in my src folder of my RestServer project.
I saw that it can be cause by conflict between libraries, so i tried to remove some in one project and let them in the other.
I cleaned and rebuilt the projects between each changes.
I tried adding the import that seems to cause the problem by adding import org.apache.hadoop.hbase.filter.*; in the files that are involve in the execution.
I have no idea of what i can do now. Some of my friend have the same problem, even if we don't have the same code, so it seems that the problem come from the configuration. At this point, i didn't perform any mapreduce job, i'm just using Hbase java api to scan the table with some filters.
Thanks for reading me, i hope i'll find the answer. I'll keep testing and searching, and editing this post if i find something.
Here is the code for the Response1 class :
package bdma.bigdata.project.rest.core;
import java.io.IOException;
import org.apache.hadoop.hbase.filter.Filter.*;
public class Response1 {
private StudentBD student;
private Semester semesters;
public Response1(String id, String program) throws IOException {
System.out.println("Building student");
this.student = new StudentBD(id);
System.out.println("Building semester");
this.semesters = new Semester(id,program);
}
#Override
public String toString() {
return student.toString()+" "+semesters.toString();
}
public static void main(String[] args) throws IOException {
Response1 r = new Response1("2005000100", "L1");
System.out.println("AFFICHAGE TEST");
System.out.println(r);
}
}
Edit
I finally managed to resolve my problem. I put the solution here, if it can help someone in the same situation as mine in the futur.
Once you've linked your 2 projects (in the Java Build Path section of the properties of the Rest api project), you need to go, still in the properties, in the Deployment Assembly (above Java Build Path). Here you click on Add... and add all of your jar files.

Intellij setup for Java graphics

How to write the BouncingBall program in Intellij . . . I'm trying to use multiple sources of information to get a good grasp of Java. To this end, I've taken the Udacity Intro to Java course, downloaded Intellij-IDEA, use the Sololearn App, and have been watching a series of lectures posted to Youtube by Stanford University. I'm trying to copy the program from Mehran Sahami's tenth lecture in the series https://www.youtube.com/watch?v=YpZCKVG4s5k&t=1995s but can't get it to run. I'm assuming that there are elements required for it to run that are not being properly imported or invoked. But, being a novice, at both Java and Intellij, I'm not sure where to start.
Here's how my code starts, anything obvious leap out? Is anything here calling for files or classes I need to install into the source or project folders, JDK, or elsewhere?
<import acm.program.*.r[]
public class BouncingBall extends GraphicsProgram{
private static final int DIAM_BALL=30;
private static final double GRAVITY=3;
private static final int DELAY=50;
private static final double X_START=DIAM_BALL/2;
private static final double Y_START=100;
Certain terms in the IDE are shown in red and the tooltip indicates "Cannot resolve symbol(or method)". This also suggests to me that the tool cannot reach the required classes or files. So . . . how do I fix that?
Thanks in advance!
I think it should be
import acm.program.*;
import acm.graphics.*;
import acm.util.*;
import java.applet.*;
public class BouncingBall extends GraphicsProgram {
private static final int DIAM_BALL = 30;
...
The imports just be folded in the video.
Also download the acm.jar into your project directory and right click the jar file, select Add as Library will add the jar file to project in intellij.

Minecraft forge not loading textures

I'm trying to teach myself java syntax and using minecraft as a platform for diving in. I'm having a problem though because none of my textures are being loaded. For that matter neither are my localizations. Here is the code for my block
package net.richbaird.testtutorial.blocks;
import cpw.mods.fml.common.registry.GameRegistry;
//import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.richbaird.testtutorial.lib.constants;
public class OrangeBlock extends Block {
private String blockName = "orangeBlock";
public OrangeBlock() {
super(Material.rock);
this.setBlockName(constants.MODID + "_" + blockName);
this.setCreativeTab(CreativeTabs.tabBlock);
GameRegistry.registerBlock(this,blockName);
this.setBlockTextureName(constants.MODID + ":" + blockName);
//LanguageRegistry.addName(this,"tutorial block");
}
}
here is my constants class
package net.richbaird.testtutorial.lib;
public class constants {
public static final String MODID = "testtutorial";
public static final String MODNAME = "Test Tutorial";
public static final String VERSION = "1.0";
}
I have my texture saved at
~/IdeaProjects/testmod/src/main/resources/assets/testtutorial/textures/blocks/orangeBlock.png
According to the log it is unable to find my texture. Here's the message I'm getting
[08:08:14] [Client thread/ERROR]:
Using missing texture, unable to load
testtutorial:textures/blocks/orangeBlock.png
java.io.FileNotFoundException: testtutorial:textures/blocks/orangeBlock.png
The client loads and my item shows up but with a default black and purple texture. What have I done wrong? I'm thinking it might have to do with my naming conventions, since the .lang file never gets read either, and the only way I can give my block a friendly name is with the now depreciated LanguageRegistry.addName() method
For those who are curious, it's a bug with intellij 14 looks like. Adding this line to the bottom of the build.gradle that comes with forge
sourceSets {
main { output.resourcesDir = output.classesDir }
}
And running gradle setupDecompWorkspace idea --refresh-dependencies
fixed the problem.
I recently ran into this bug after updating IntelliJ, and while richbai90's solution did fix the immediate issue, it also broke compiling the mod into a jar (the assets folder gets included twice). After some digging around, I eventually found the root of the issue: IntelliJ was delegating the build task to Gradle, which put the assets and classes in separate folders, and Forge didn't know they belong to the same mod. The solution that worked for me was to build and run using the IDE, which is in the Settings dialog under Build, Execution, Deployment | Build Tools | Gradle (the help page has more detailed instructions). On older versions of IntelliJ, this was called "Delegate IDE build/run actions to gradle" (see the help page).

Debugging java source file with multiple classes in eclipse: Source not found

I have similar problem to the one described here:
Eclipse and Java - source not found
I also looked at the following question: Eclipse java debugging: source not found but I could not see how that it applied to my case..
I have just started using Eclipse and its debugger.
Here is how to reproduce the problem using Eclipse 3.7.2 on Ubuntu 12.04 with java and javac version 7.
Start Eclipse and select workspace, e.g., "Test" in home folder.
Open java perspective
Open new java project with project name "Test"
Add a new java class "Test"
I now have the following screenshot:
Add the following code to the source file Test.java
set a breakpoint at new Test2(1)
open debug perspective
start debugging:
choose Step Into (F5)
Now the error is reported:
Any help on this issue is appreciated..
The class Launcher$AppClassLoader belongs to the JRE and is about to load your class. It has nothing to do with the source code of your own classes. If you step further you will reach your own class Test2. If you go to the end of your debug button bar (four buttons right to the “step into” button), there’s a “Use step filters” button. Activate it to avoid unnecessary steps into the JRE classes.
I believe you have to create an instance of Test before you can access the nested class Test2 in Test. Eclipse should have thrown an error in yours saying something like "No instance of Test2 is accessible" or something like that. Change your code to look like this and see if it works.
public class Test {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Test mTest = new Test();
Test2 nTest = mTest.new Test2(1);
}
class Test2{
int i;
Test2(int i){
this.i = i;
}
}
}

Can I use Ant to set some static variables in my Android project when building?

I would like to automate my Android project building with Ant. Currently I have to change some static String and Boolean fields in one of the classes for different kind of versions of the same app for different markets.
Is it possible to set these variables with Ant, without resorting to copying a file with some strange markers in it? I want to be able to keep using the files in Eclipse.
You can, but you shouldn't. Don't make your Ant build file mess with the code; it leads to strange and confusing errors that are hard to find.
Instead, use java Properties.
Here's a little example of how a static final can be initialized in a static block:
class Junk {
public static final int j ;
static {
// Use java.lang.Properties here to get the values
j = 42;
}
public static void main(String[] argv){
System.out.printf("The answer is %d\n" , j);
}
}
Yes you can.
When copying, use a filterset. Include a few filter tokens to be replaced in the text file, and in the filterset specify the token and the value to replace it.
<copy todir="../backup/dir">
<fileset dir="src_dir"/>
<filterset>
<filter token="TITLE" value="Foo Bar"/>
</filterset>
</copy>
Note that you must do this prior to attempting to compile the file, so you might have to rework a bit of the compiling logic to be compatible with the filtered copy.
Personally, I make a build/processed-src directory and copy everything into it filtered (copy will only update out-of-date files) and then rework the compile chain to compile from there.
Possibly you can create a stub "java" file which is "echo"ed out as part of the ant build.
<echo file="com/corp/product/Version.java">
package com.corp.product;
public class Version {
public static final int MAJOR = ${version.major};
public static final int MINOR = ${version.minor};
public static final String full = "${version.major}-${version.minor}";
}
</echo>
It gets around most of the complaints about having to copy, but it does mean that the class will have to be maintained within the ant build file (or in an included ant build file).

Categories

Resources