Android studio library dependency not showing up - java

I went to file -->app--> dependencies --> green plus sign and press on library dependency. Nothing show up. I trying to add the support v4 dependency so I can extend Fragment Activity. Now I having error cannot resolve symbol support.
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
ViewPager viewpager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewpager = (ViewPager) findViewById(R.id.pager);
PagerAdapter padapter = new PagerAdapter(getSupportFragmentManager());
viewpager.setAdapter(padapter);
}
}

Open the build.gradle file for your application and add this line compile "com.android.support:support-v4:18.0.+"
Make sure you have downloaded the Android Support Repository using the SDK Manager.
ref here

Related

Error: Unexpected implicit cast to `ConstraintLayout`: layout tag was `TextView`

It seems like there are a lot of questions regarding TextView and such but I am completely new to coding. I am working in Java language in Android Studio trying to make an app, I am doing this by following another persons instructions on YT, they do not get this error.
Here is the code:
package com.example.soudsrestautantcuisine;
import...
public class IntroActivity extends AppCompatActivity {
private ConstraintLayout startBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
startBtn=findViewById(R.id.startBtn);
This code is not finished but I get the error at this last line here regardless of whether the whole code is written.
May somebody please help me ?

Android Studio not recognizing Java objects

For reference I am using Android Studio 3.1.4. My problem is that android studio isn't recognizing any of my java objects aka all of the objects names are underlined in red. Here is the code for my main activity:
package com.example.t00587599.unitconverter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AdapterView;
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context: this, R.array.temptypes, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}
}
I donot know much about the issues that you are facing as there can be multiple reasons why that is happening. There are two things that you could be happening
- if your package is compiled then you should check if the files are in the project. Or the project where the package is included is added in the build.gradle. I do this by adding
compile ":unitconverter"
- if you are including this as a compiled dependency then you can add the following line in your build.grade for the project
compile "com.example.t00587599.unitconverter"
After that you should do a gradle sync. If after doing all this you still get the red lines then you should do a "File/Sync Project with Gradle Files" from the file menu.
All of these class of problems disappear after these steps for me.
If it still appears then you should give us the error that come when you highlight it.

Material Design ToolBar with ListActivity

I am replacing the ActionBar and integrating the Material Design ToolBar within my app. One of my activity's extends ListActivity.
In the onCreate() method, whenever I try to add the ToolBar, the setSupportActionBar() method is producing an error saying it cannot be resolved.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_route_recipients);
// Attaching the toolbar layout to the toolbar object
toolbar = (Toolbar) findViewById(R.id.tool_bar);
// Setting toolbar as the ActionBar with setSupportActionBar() call
setSupportActionBar(toolbar);
// get the default list view associated with this activity
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // we can now check and uncheck multiple friends
// get the array of LatLng points passed in from the map intent
markerPoints = getIntent().getParcelableArrayListExtra("markerPoints");
}
What is the best solution to this problem?
You wrote that your activity extends ListActivity but sadly ListActivity doesn't implement setSupportActionBar. You have to base your activity on AppCompatActivity.
You'll say "but hey, but I really need ListActivity as I've ListView in my Activity" -- consider using RecyclerView as well. I'd say that ListView is a dead end now -- one should port code to RecyclerViews
And as a help, two sample projects showing all new features of Material Design
https://github.com/antoniolg/MaterializeYourApp
https://github.com/chrisbanes/cheesesquare

build.xml:1: Premature end of file

I am new in Android development, and I wanna build some apps for myself. I have installed Android SDK last version, NetBeans IDE 7.4 and also the plugin for this. I wrote a simple code for Android to see if it works:
package com.app;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity 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("HelloWorld");
setContentView(tv);
}
}
When I try to build and run with an emulator, I get this error: [path] \AndroidApplication1\build.xml:1: Premature end of file.
When I go to the file (build.xml) I see that is empty. I should write to it? What should I do? Thanks in advance.

Just update ADT and Unable to resolve superclass errer appear

The error show after I update my ADT, the project is created before the update.
In Login Activity,
public class LoginActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Do something here... if login success, Start another activity
Intent i = new Intent(LoginActivity.this, MainActivity.class);
LoginActivity.this.startActivity(i);
}
.......
}
In MainActivity,
public class MainActivity extends FragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
//......
}
}
I try to remove all the code inside and back to a blank activity. The error is not happen because of the code inside the activity. I think is abut the extend FragmentActivity
Here is the error trace:
Unable to resolve superclass of Lhk/iactive/imoodle/activity/MainActivity; (15)
Link of class 'Lhk/iactive/imoodle/activity/MainActivity;' failed
I get this error after I update my ADT.
I do some research on this topic. I try to import the android-support-v4.jar again and this do not fix the problem.
I also read some blog like THIS ONE can not help me too :(
I have solve the problem by myself. I am going to share the solution hope there is other people who suffer from the same error can save some time :D
I try many method for example go to build Path Config -> Order and Exprot, All the library is already checked. And the NoClassPathFound error is still showing.
I have no external Jar for the project and The error is from FragmentActivity from Android Support Library.
Then I delete the android-support-v4.jar complete and add it again by right clicked the project -> Android Tools -> Add support library...
After the new support library added. All the error fix. :D
This worked for me:
For all projects (app and library):
Right click the project, and choose Properties
Go to Java Build Path-Order and Export.
Tick 'Android Private Libraries'

Categories