Create New Activity Error: RED SQUIGGLYS EVERYWHERE - java

So I have been working with Eclipse and Android Application projects for a few months now, and recently, I have had some problems.
So to give the full backgroud, I changed the target SDK and API of a project, and downloaded every SDK package available. Since then, I have had numerous problems with my programs. But now, everytime I created a new Android Application Project, everything that is auto-generated by Eclipse has a red squiglly line under it and an error message stating that the method "must override or implement a supertype method" or that the "method is undefined" or "cannot be resolved to a type".
I have attempted a Clean and have restarted. I changed the SDK level and the API.
![this is a shot of my code.][1]
Here is my code from my Main Activity file.
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
These are the errors that show up on the bottom of Eclipse in the console.
*Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
*All versions of the libraries must be the same at this time.
*Jar mismatch! Fix your dependencies
I'm not sure what to do, and apologize for providing so much information. Any help would be greatly appreciated!
UPDATE: Now, when I create a new Android Application Project, there is nothing in the src file. I really have no idea what the heck is going on.

This happens when you have added the support jars to your main project and also to library projects. They all come bundled together. Make sure any of your library projects don't have the support jars added to them as libs. If they have and u need them to be there then remove those library jars associations from your main project.

I had the same kind of problem. They way I fixed it was that I used only the latest version of SDK. I had to get rid of all the other SDK packages.

Related

can not click action bar app icon Android

I'm trying to make the action bar app icon (top left image) clickable but it just doesn't work, I've already searched for some answers but nothing works. I've already tried to getSupportActionBar().setHomeButtonEnabled(true); and I can see the icon, but i still can't click on it. I know I can handle the event in the method onOptionsItemSelected(MenuItem item) but the event will never get triggered with my situation. I also don't get why I have to use getSupportActionBar(); instead of getActionBar()...the second one is always null. The minimum sdk is 16 and the maximum is 22. I read this answer -> ActionBarCompat - App icon action (click) not working on 4.0 devices but I don't know how to get in the ActionBarHelperICS.java class or if it apply to my case.
You haven't really posted any code. But there may be 2 problems.
You have to specify which is the parent activity in your manifest file.
Under the activity's tag in manifest, you'll have to specify which activity your home button will point to. Something like this:
android:parentActivityName="com.example.app.MainActivity"
Or Override your onOptionsItemSelected
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
//add what you want to do here...
return true;
default:
return super.onOptionsItemSelected(item);
}
}

How do I add a new page to an Android app?

Apologies for the basic question, but I can't really find the answer online. Possibly because I'm not sure what I need to be searching for!
I have created a simple one page app following a guide. At the top there is a menu button, under that 'Settings'. I want to make it so that when the Settings button is clicked it takes you to a new settings page and allows the user to change the background colour, font colour or something simple like that.
However, I can't work out how to actually create a new page. I tried creating a new class and linking the intent under the action_settings bit in the main .java file, but that didn't work for me.
Please could someone give me some guidance?
GitHub repo: https://github.com/LewisLebentz/Quoter
If the settings button is on the action bar then follow these steps:
1) Create a new activity by right-clicking on the Java folder > New > Activity > Blank Activity. This will automatically create a layout file and a Java class. It will also automatically register the activity in the manifest.
2) Next you want to go to the Quoter.java file. Add the following code to it.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
// This code will start the new activity when the settings button is clicked on the bar at the top.
Intent intent = new Intent(Quoter.this, newActivityName.class);
startActivity(intent)
return true;
}
return super.onOptionsItemSelected(item);
}
That's it! When you click the settings button, it should start a new activity! Let me know if it does not work!
By the way, you can search for "how to switch activity on button press in Android".

Cannot find symbol class Intent

I am new in android development and coding java and xml.
but I was following this tutorial:
http://www.steventrigg.com/activities-and-the-action-bar-create-an-alarm-clock-in-android-tutorial-part-1/#comment-296
then I had this error when using Intent. The word "Intent" under switch became red and there is an error "cannot find symbol class Intent"
Can someone explain to me what is going on and how to solve this?
This is the last part of my code under AlarmListActivity.java
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
switch (item.getItemId()) {
case R.id.action_add_new_alarm: {
Intent intent = new Intent(this,
AlarmDetailsActivity.class);
startActivity(intent);
break;
}
}
return super.onOptionsItemSelected(item);
}
Look at your AlarmListActivity again and check the import statements at the top and make sure it includes the line:
import android.content.Intent;
If you intend to use any pre-existing classes that aren't part of the java.lang package, you generally have to import those classes. An Android Intent, for example, is a pre-built class, written by the Android development team, that allows for notification of other apps/activities. If you want to use Intent, you'd then have to import the package containing Intent.
When you write new Intent(), the compiler sees that you're requesting the construction of a new object, but because that object is not found in the java.lang package, it needs to know where to look for a blueprint to build that object. The import statement is the location of that blueprint.
I took a look at the tutorial and in the manner of experienced programmers, the author seems to have glossed over a few basic, but nonetheless, important things, such as the import statements that make his sample code work.
I had a same problem which I just resolved, by understanding how Android Studio indexes files, As you know Building an Android App is quite complicated process. So Android studio has some internal references which it keeps getting updated on change of every file that you have created.
I arrived at this post while searching for the solution,
This is how I got this problem
I usually wont create an activity under the main project package, I create sub packages to organize files as per the design pattern that I use, for eg If my APP name is com.example.testingaravind then inside that I usually create packages such as activites, services, models, managers etc ... So today I just created an activity first and then moved that activity into activites package via Android Studio, I started facing the same issue what you have described, Below was my source code
public class BootstrapActivity extends ActionBarActivity {
private static final String TAG = "BootstrapActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bootstrap);
}
public void startServiceOnClickHandler(View view) {
Intent intent = new Intent(BootstrapActivity.this , AnalyzerService.class);
startService(intent);
}
}
In the method startServiceOnClickHandler it was showing an error saying,
"Cannot resolve constructor Intent" I searched a lot in google and found that
When I move a file from one package to other package, my manifest file wont get updated, in the manifest we mention the activity name and its package path in my case it should be
android:name=".activities.BootstrapActivity"
But it was
android:name=".BootstrapActivity"
Because of this, Android studio was unaware that a class called BootstrapActivity exists inside the activities folder,
This seems to be a bug in the way how android studio works. Android Studio has to update manifestfile when I move the activity class file from one package to another package.
I am posting this to help others who might arrive at this post with the similar usecase.
Check name in manifest file in activity tag specify correct package for example your
<activity
android:name="Your-Package.MainActivity"
android:exported="true" />
In second case If you are using kotlin class inside java class, after configuring kotlin in project can solve the project...

Reference to class file not working

I'm trying to make a simple RSS feed reader app. I've created a class file with the name "IotdHandler.java" and a public class with the same name. When I try and create a new instance of the class I get the following error: "Unreachable code".
If anyone can point me in the direction of a good tutorial about working with multiple class files I would be very grateful.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.nasa_daily_image, menu);
return true;
IotdHandler handler = new IotdHandler();
handler.processFeed();
}
Thats because you have a return statement before.
Unreachable code has nothing to do with the class/library, is a compiling error because there's no way the code below the "return true" will be executed in anyway, you should get a good Java Book before diving into Android.
Regards!

ActionBarSherlock - Share Content icon issue

I am using ActionBarSherlock and have implemented ShareActionProvider.
When a user selects an app to share content with, eg Twitter, the actionbar displays a Twitter icon next to the Share button icon. This stays there forever.
Does anybody know how to disable the application icon from appearing next to the Share button?
Found the answer:
Implement OnShareTargetSelectedListener and set it on the
ShareActionProvider
public void onCreateOptionsMenu(Menu menu){
....
actionProvider.setOnShareTargetSelectedListener(this);
....
#Override
public boolean onShareTargetSelected(ShareActionProvider source,
Intent intent) {
context.startActivity(intent);
// started activity ourself to prevent search history
return true;
}
The top target is featured in the action bar. This is the behavior of the widget as it exists in Android.
If you do not want this behavior copy the sources into your app and modify its behavior to never display the top target icon.

Categories