I have never used Android Studio before and have always been coding using NetBeans.
I need to create an app for Android, so I decided to use NetBeans. I created new project and it is 'empty' for now, however I have an error:
package Fridge.Freezer;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
The error is in setContentView(R.layout.main); - cannot find package. Can anyone tell what I am doing wrong? Clean and build does not work.
erase your package name at the top and try to add it to getting the suggestion package import by shortcut Control + Enter beside "R"
Try checking following component in your project directory
R.java file
folder named layout
layout xml file named main.xmlmain
PS Since your are starting a fresh project, I would suggest you to start at Android Studio.
I tried cleaning the project and rebuilding it again. It did not work. The solution was to restart IDE.
Related
I was making an app in android studio and i had no errors. I closed android studio but reopened it because i forgot to do something. when i went into my MainActivity.java i noticed the R was in red and i don't know why
this is the code in my java, it's not like there was something in it:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class HomeMenu extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_menu);
}
}
can someone help me ?
Ok, this is what I would do:
Clean the project
Rebuild the project
If that doesn't work, then:
Go to: File -> Invalidate Caches and Restart.
And if the previous option didn't work, then:
Check the package name in the first lines of the java files.
Create a new project and copy the content of your previous project.
I am creating simple android application in android of hello world printing and getting an -- error Description
Resource Path Location Type Error generating final archive: java.lang.ArrayIndexOutOfBoundsException: 13 Demo_ABC Unknown Android Packaging Problem
Code is:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Someone else had the same problem with eclipse. The solution was to check the box "Create Test Project":
Your project is getting associated with some Test Project which you are not mapping with your newly created project. When you are creating any new project check carefully whether you are including the "Create Test Project" option or not.
Another guess: As the error seems to be package-related and your code does not include that, insert the correct package yourpackage.tld; in the code. (you said "Code is:").
Maybe that is missing Android expects it by default and gives weird errors because that was totally unforseen by the Google Android developers.
I am running Eclipse Indigo with Android SDK 4.0.3 and Google API in Linux 11.10. However, when I start up a new Android project, my R.java is no where to be found, hence resulting in the following issue:
package com.lol.asdf;
import android.app.Activity;
import android.os.Bundle;
public class AsdfActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
I have tried all suggestion on this page but it's no good.
Anyone have any ideas?
your R.java is an auto generated class from the res/ folder. Check for error inside it. Try clean and rebuild your project too.
R.java will generated automatically...
first solve all other errors of your project it will be created...
I have two classes in a different projects.
I am importing the project that has the class that I need.
Now, I have no errors.
The project know's that class and I even made an object from that class, but when I'm trying to run it it crushes with the "NoClassFoundError".
How can i fix that?
import com.dmg.pixelservice.core.*;
import android.app.Activity;
import android.os.Bundle;
public class show extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Pixel pixel = new Pixel();
pixel.doIt(this,"fd7ccf36-3f85-11e1-8671-40409e0f44a1",true);
setContentView(R.layout.main);
}
}
When I debug, I can see that it crashes when I'm trying to do Pixel pixel = new Pixel();
Please help.
create new libs folder in your application .name must be same.and put your jar files in this folder.and
go to
java Build Path -> Configure Build Path -> Add jars
Looks like the jar file containing the Pixel class is not packaged into the APK.
To make that happen, it seems you need to copy the jar into the libs folder of your Android project.
See this question:
Approach for fixing NoClassDefFoundError?
Android Developer Guide:
http://developer.android.com/guide/developing/projects
it is easy to find the error if you send the src code of your Pixel class.
When I try to run the Hello, Android Activity, it says: emulator: ERROR: no search paths found in this AVD's configuration.
And underneath that it says: Weird, the AVD's config.ini file is malformed. Try re-creating it.
I'm stumped and would really appreciate if someone could help me out.
This is what I have for the code:
package my.helloandroid.activity;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroidActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
Check the manifest file or look here:
Trouble getting Android emulator to run in eclipse
Three things which came to my mind.
Be sure to check if you have correct path to avd, Window->preferences.
Press right mouse button on your project folder and use android tools -> fix project.
simply restart eclipse.