Android. Support4Demos crashes - java

I have runtime errors while executing Support4Demos sample.
I'm trying to launch Support4Demos sample (both on emulator and device). There are no errors in Eclipse and it's launched well. As you know first I should select category (for instance "Fragment"), then subcategory (for instance "Tabs"). And after I've selected subcategory - app crashes with following log
12-27 16:39:51.796: E/AndroidRuntime(384): FATAL EXCEPTION: main
12-27 16:39:51.796: E/AndroidRuntime(384): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.supportv4/com.example.android.supportv4.app.FragmentTabs}: java.lang.ClassNotFoundException: com.example.android.supportv4.app.FragmentTabs in loader dalvik.system.PathClassLoader[/data/app/com.example.android.supportv4-1.apk]
I did't make any changes in the source code. May be I missed something?
Could anyone help me?

You should put the android-support-v4.jar to the directory named "libs" of your project and then refresh the project.

If you add the android-supportv4.jar it will work. Here are some detailed instructions on how to do that:
http://developer.android.com/tools/extras/support-library.html#Downloading
You need to follow every step to a "t" in that link. However, sometimes the instructions
are not very clear. So, I will try to explain what some of the instructions mean:
I found the .jar file which I needed to add in the following directory:
C:\Users\nadir\android-sdks\extras\android\support\v4
the steps say, In Eclipse, right-click the JAR file in the Package Explorer, select Build Path > Add to Build Path
Let me show you what that looks like on my computer:
the instructions also say: select Build Path > Add to Build Path, you may not find it worded exactly like that. Here is what I did, i(note: I clicked on the "add external JARs" button):

Be sure that android-supportv4.jar is in your classpath.
The jar is located under /extras/android/support/v4/android-support-v4.jar

Related

Eclipse launch config fails for classes in second source folder

I create the simplest possible modular project in Eclipse 4.21.0 (see below), with two source folders and one package. Both main methods just print "Hello".
If I right-click on Main1 and Run as Java Application, it's all fine.
If I right-click on Main2 and do the same, I get:
Error: Could not find or load main class p1.Main2
Caused by: java.lang.ClassNotFoundException: p1.Main2
If I check the two run configurations this generated (Main1 and Main2), they are (superficially) identical, except for the name of the Main class. If I go into the Main1 launch configuration and change the main class to Main2, now it works. So Eclipse generated a valid launch config for the top source folder, and a broken one for the second source folder.
Why is this, and how can I generate valid launch configs for other source folders?
Details
I'm aware that this is not an issue for non-modular projects, but I'm interested in solving the case for modular projects.
This happens even when I delete/refresh the launch config before launching, and independently of the order I run Main1 and Main2.
This happens whether I have a single output folder or one per source folder.
This turns out to be a known bug reported on 2020-11-23 for version 4.17: Cannot launch class if module-info.java is in additional source directory.
Workaround
As indicated in the original bug report, attempting to modify the broken configuration does not solve the problem:
If I edit the launch configuration (even if I just change the name) I get the following error instead on launching: Error occurred during initialization of boot layer...
However, it is possible to create a valid configuration for the main source folder (where module-info.java is located), and modify that configuration to use a main class from the additional source folder, which will run fine.

Can't resovle a class in jar that already added in my project

As you can see from the pic, StdOut is a error for can't be resolved. But when I click it with holding Ctrl, I can still open the StdOut.class(Also in pic,you can see it) And StdOut class is in stdlib.jar which is in Referenced Libraries in left of pic. I just want to use StdOut.class. What should I DO?
Try adding the jar as an external jar
BuildPath>>Configure BuildPath >>Libraries>> Add External Jar
Also try importing the full path of StdOut before using it.
I found a stupid solution: find the StdOut.class and copy the content from it, make a new package in my project and paste it. Although it's stupid, but this time StdOut.class can be resolved (the Eclipse can resolve my knew package).

Where is the R.java file in Android Studio?

Where is the R.java file in Android Studio? Can someone please help with this? I already tried google for the answer but can't find any solution.
Based on the new stable release of Android Studio (3.6) we have:
So, now to find your generated resource classes you need the following steps:
1) Open your project.
2) Go to your module build path.
3) Open the outputs/apk/debug/app-name-debug.apk file.
4) Choose your classes.dex file.
5) Look at the down placed area and go to your full package path.
6) You can see all bytecoded resource classes. So, scroll down to what you are looking for.
7) Expand the resource class you need to proceed (for example, let it be R.id)
8) Go to you id's.
That's it.
UPDATE:
If you would like to see actual id integer number you should follows steps below:
1) By (7) Go to the resource class you need to proceed and right click to show the context menu
2) Choose "Show Bytecode" to see the flexible dialog "DEX Byte Code for R$id", for example, for id class
3) Scroll down to the actual id to look its number
Although the current Android Gradle Plugin doesn't generate a R.java anymore you can still inspect the corresponding class file (see Sergey V.`s answer).
However, if you (like probably in most cases) just want to look up the generated IDs for your resources, there is an easier way:
In the project pane on the left hand side switch from Android to Project view using the drop-down at the top. Then navigate to app/build/intermediates/runtime_symbol_list/<insert build type here>/R.txt. This file lists all IDs generated by AGP during the build process.
I use Android Studio 3.3.2
\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\android\support\constraint\R.java
As noted above, "The new Android Gradle Plugin generates the corresponding bytecode directly and does not make the intermediate R.java file".
Using the ubuntudroid solution you can find an id also this way. Find R.txt and copy absolute path. Project > app > build > intermediates > runtime_symbol_list > debug > R.txt. Then right click and select Copy Path..., 1. Absolute Path Ctrl+Shift+C.
This way you will obtain a path to R.txt, for instance, "C:\Users\user\AndroidStudioProjects\your_project\app\build\intermediates\runtime_symbol_list\debug\R.txt". Copy the path without R.txt to a text file for future references, for example, with Notepad++.
Press Ctrl+Shift+F to find in directory. Insert an id and the path.
== Old answer ==
Change a project view from Android to Project or Project Files. Find one of these two files.
Then you can revert back to Android view.
I use Android Studio 2.3.3. The R.java file is shown in the picture above.
In the left upper side, there is a select list. Select the [project] option so that you can see all the folders and files.
R.java is the generated file by ADT or Android studio. It will be located under app\build\generated\source\r directory.
./app/build/generated/source/r/debug/android/support/v7/appcompat/R.java
./app/build/generated/source/r/debug/your/packagename/name/R.java
I am using Android Studio 2.2.3 , the R.java file is shown in the picture below.
Goto in the left upper side there is a selecting list ,
select [package]
Open "App Folder"
com.example.saeedanwar.myapplication;
r
In my project in Android Studio 4.1
R.jar that you can actually unzip resides in app build folder, as follows:
jar -xf R.jar
Once the jar is unpacked you can find R.java inside of app package:
If you're using Mac or Linux, try the following command line on your terminal:
find . -name "R.*"
It will print something like:
./app/build/intermediaries/runtime_symbol_list/debug/R.txt
./app/build/intermediaries/compile_and_runtime_not_namespaced_r_class_jar/debug/R.jar
It is inside app\build\generated\source\r folder
Project/app/build/generated/source/r/debug/com.android.'projectname'/R.java
--The R.Java that contains your xml layouts and views id's in Android Studio 3.5.3 -- Project/app/build/generated/not_namespaced_r_class_sources/debug/r/com/"your package"/R.java
This answer will be in a constant state of flux until Android standardize a method of matching their annoying decimal/hexadecimal id references to a tangible resource such as my_layout.xml.
For Android Studio Dolphin | 2021.3.1 Patch 1 have a look at this file:
/project/package/build/intermediates/stable_resource_ids_file/debug/stableIds.txt
It is produced by RUN (not just BUILD). Sample:
layout/mtrl_picker_header_fullscreen = 0x7f0d00de
string/cancel = 0x7f1101f0
style/ThemeOverlay.MaterialComponents.MaterialCalendar = 0x7f1202f3
id/gpxBtn = 0x7f0a0346

How do I import ShowcaseView in Eclipse?

ShowcaseView is contained in a Zip file here. But what exactly am I downloading and how do I import it in Eclipse?
After 2 days I succeed, I have created steps to import ShowcaseView in Eclipse that may be helpful to you.
How to use Showcase View in Eclipse.
Download ShowcaseView from github and extract.
Now Follow step for import.
- Right click on Project Explorer
- Import -> Android -> Existing Android Code Into Workspace
- Select Extracted "ShowcaseView-master"
- Check both project "library" and "MainActivity"
- Check "Copy projects into workspace"
- Finish.
(After importing you can see 2 projects imported namely "main" and "SampleActivity", you may change "main" as "libShowcaseView" and "SampleActivity" as "ShowcaseViewDemo" so you can easily identify. :) )
May you see error in "ShowcaseViewDemo" (Dont worry...), See src/ folder is also blank (in both "libShowcaseView" and "ShowcaseViewDemo") :) right??? Dont mind.
Make following packages in "libShowcaseView" project. See Example.
- com.github.amlcurran.showcaseview
- com.github.amlcurran.showcaseview.targets
and Move all java files from /java/com/github/amlcurran/showcaseview and /java/com/github/amlcurran/showcaseview/targets Respectively.
Make following packages in "ShowcaseViewDemo" project. See Example.
- com.github.amlcurran.showcaseview.sample
- com.github.amlcurran.showcaseview.sample.animations
- com.github.amlcurran.showcaseview.sample.legacy
- com.github.amlcurran.showcaseview.sample.v14
and move files as above (from java folder respectively).
Now right click on "libShowcaseView" project->properties->Android->Move down and check "Is Library" then add "actionbarsherlock" as Library. See Preview
Now Add as library in ShowcaseViewDemo. Goto properties of "ShowcaseViewDemo"->Android->Add->select "libShowcaseView"->Ok...
I think you didn't ran into error now. You can Run.
You can ping any time for any suggestion or help.
Happy ShowcaseViewing...
Easiest way is:
Create an empty Android Application project in your Eclipse workspace.
Copy files in ShowcaseView/library/ folder of github to your new project base folder.
Refresh project in Eclipse.
Goto project properties - Android and select "Is Library"
Clean unnecessary stuff and build.
It should be ready to add as dependency of your app.
Alternatively you can pick another library project .project file and copy it inside this library folder, edit it to match your new project name, etc... And then import in Eclipse. But this is more hardcore if you don't know what you're doing.
Soure : How do I build these libraries from GitHub
Following ツ Pratik Butani ツ's Answer and use Android Support Library to replace ActionBarSherlock
In project.properties of libShowcaseView and ShowcaseViewDemo
add target=android-21
Right click on "libShowcaseView" Properties->Android->Library->Add... select AppCompat(android support library v7)->Ok
In styles.xml of ShowcaseViewDemo
Change
android:Theme.Holo.Light, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar to Theme.AppCompat
Remove <item name="android:fontFamily">sans-serif-light</item> in ListItemBigText
In ActionItemsSampleActivity.java
change SherlockActivity to ActionBarActivity, getSupportMenuInflater to getMenuInflater.
In MultipleActionItemsSampleActivity.java
change SherlockActivity to ActionBarActivity
change com.actionbarsherlock.app.ActionBar.OnNavigationListener to android.support.v7.app.ActionBar.OnNavigationListener
changegetSupportMenuInflater to getMenuInflater
Do it in there steps:
Download ShowcaseView from github`
Create package com.github.amlcurran.schowcaseview and com.github.amlcurran.schowcaseview.targets in your eclipse project.
Extract ShowcaseView-master.zip or rar.
Go to library/src/main/java/ and copy com/github/amlcurran/showcaseview java files in com.github.amlcurran.schowcaseview package.
Do same thing for com/github/amlcurran/showcaseview/targets in com.github.amlcurran.schowcaseview.targets.
Finally, copy others files in differents folder drawables, layouts, value(copy in the old value files, style.xml for example).

Error: Selection does not contain a main type

I am trying to run some java files in a new project. So I make the project, put the files in it and I try to run the main file so my game starts.
I get an error that says selection does not contain a main type.
I have tried several ways to run it:
Some say to launch eclipse again, tried this a dozen times.
Somewhere else someone pointed to open a new project and make a build path to the old project.
Didn't work either.
I am pretty sure it must work because I ran it a few hours ago at school. How do I get this working? Thank you in advance!
Right click on the folder where you put your main class then click on Build Path --> Use as Source Folder.
Finally run your main file as java application. Hope this problem will be solved.
If the option 'Use as Source Folder' is not visible then inside the 'Build Path' select the option 'Remove from Build Path'. This will allow 'Use as Source Folder' option to appear in the 'Build Path'.
The other answers are all valid, however, if you are still having a problem you might not have your class inside the src folder in which case Eclipse may not see it as part of the project. This would also invoke the same error message you have seen.
I hope you are trying to run the main class in this way, see screenshot:
If not, then try this way. If yes, then please make sure that your class you are trying to run has a main method, that is, the same method definition as below:
public static void main(String[] args) {
// some code here
}
I hope this will help you.
The entry point for Java programs is the method:
public static void main(String[] args) {
//Code
}
If you do not have this, your program will not run.
I resolved this by adding a new source folder and putting my java file inside that folder. "source folder" is not just any folder i believe. its some special folder type for java/eclipse and can be added in eclipse by right-click on project -> properties -> Java buld path -> Source and add a folder
Few things to check out:
Do you have a main package? do all of your classes are under this package?
Do you use a main class with public static void main(String[] args)?
Do you declare: package ; in your main class?
You can always clean the project before running it. In Eclipse - Just go to Project -> clean then run the app again.
I ran into the same problem. I fixed by right click on the package -> properties -> Java Build Path -> Add folder (select the folder your code reside in).
I am running eclipse from Ubuntu. Had this same problem and was able run the program through terminal. So I just moved the existing public static void main(String[] args) { just below the class declaration (it got automatically formatted by eclipse) and the next launch was successful. Then moved the main method back to where it was before and it worked fine this time.
I had this problem in two projects. Maven and command line worked as expected for both. The problems were Eclipse specific. Two different solutions:
Project 1): Move the main method declaration to the top within the class, above all other declarations like fields and constructors. Crazy, but it worked.
Project 2): The solution for Project 1) did not remedy the problem. However, removing lombok imports and explicitly writing a getter method solved the problem
Conclusion:
Eclipse and/or the lombok plugin have/has a bug.
Looks too late to answer but might help someone,
Having same problem i solved it by following steps:::::
Select Main class in eclipse then click on Window in menu bar,
Window-->Show view-->Select Outline
Right click on main(String[]):void then Run As --> java Application
By doing this you can run the main method directly. This worked for me
Right Click > Run AS > Run Configurations
In this screen if your "Main class" Text field is empty, then add the class name by clicking "Search" button on the right side of the text field and choose the class file. And then click "Run" button on the bottom of the configuration screen. That's it
You must place all your files (file.java) under the root folder SRC.
Make sure the main in public static void main(String[] args) is lower case. For me it didn't work when I had it with capital letter.
Put your Main Java class file in src/main/java folder and check if there is not any error in 'Java Build Path' by following right click on project and select Java Build Path->Source.
If you are working with a Maven project you have to understand the fact that directory layout is bit different. In this the package name must be src/main/java.
For this update your source folder by right click on project root folder -> properties -> java build path -> source tab. Here remove all other source folders as they might have been added in wrong manner. Now, select project /src/main/java as the source folder. Add and apply the changes. Now refresh your workspace using F5.
This should fix the issue of not recognizing a main type.
I ran into the same issue and found that there was an extra pair of braces (curly brackets) enclosing public static void main(String args) { ... }. This method should really be at the top scope in the class and should not be enclosed around braces. It seems that it is possible to end up with braces around this method when working in Eclipse. This could be just one way you can see this issue when working with Eclipse. Happy coding!
I had this happen repeatedly after adding images to a project in Eclipse and making them part of the build path. The solution was to right-click on the class containing the main method, and then choose Run As -> Java Application. It seems that when you add a file to the build path, Eclipse automatically assumes that file is where the main method is. By going through the Run As menu instead of just clicking the green Run As button, it allows you to specify the correct entry-point.
When you save your file, make sure it has the extension .java. If it does not, Eclipse won't know to read it as a java file.
I had this issue because the tutorial code I was trying to run wasn't in the correct package even though I had typed in the package name at the top of each class.
I right-clicked each class, Refactor and Move To and accepted the package name suggestion.
Then as usual, Run As... Java Application.
And it worked :)
You must check this as well, Go to Java build path -> config build path, check that JRE System Library [Java SE -version] is check marked, try running the code again. This fixed my issue.
In my case I was using ant to perform the build, and clearly had the class setup in the build.xml file:
<target name="jar">
<jar destfile="ec-stats.jar" includes="bin/**,src/**">
<manifest>
<attribute name="Main-Class" value="my.package.MyStatistics" />
</manifest>
</jar>
</target>
But it still kept giving me the same error, until I right-clicked on the folder in Eclipse and chose Build Path -> Use As Source Folder.
See also Error: Selection does not contain a main type
Solved the issue as following:
Going in Properties of the Project
1.1) Inside "Java Compiler": chose the: "Compiler compliance level:" to a specific version of JDK (in my case I choosed 15)
1.2) Inside "Java Build Path", in the tab "Libraries", at the Modulepath: change the "JRE System Library" to the same of the version you choosed at step 1.1 above (in my case I picked JDK 15)
Run the java file that contains a main method
This can be resolved in two steps if you are using Eclipse IDE.
👉 Step I: Right click on the project and click Maven > Choose Up-date Project
👉 Step II: Select the project the click Ok button
Hope this helps.✔
This error usually occurs because jdk is not selected for the project. I had the same problem and this worked for me.
Make sure that your class file is inside src folder then follow below steps
Step 1: Right click on project folder
Step 2: Build Path --> Configure Build Path
Step 3: Select "Java Build Path" from the left corner of the window
Step 4: Under "Order and Export" Tab
Step 5: Click on any of the jdk available check box to select it.
Step 6: Click on Apply and Close.

Categories

Resources