I read almost every answer obout this topi c but i cannot find a working solution for my case or maybe I'm missing somthing.
I use eclipse as IDE and I would like to use an external library for example I'm trying to add this Library to my project but I don't understand what i'm doing wrong.
I tried download the full project and import it into the workspace, mark it as library and then under my project and add it as reference.
If everything is ok how should I call an activity from the linke library?
I tried to defind the linked activity into my manifest file but without success.
Could you please point me in the right way?
Thank you
You need to write code which will call the library activity inside onCreate() or any other method which you choose like
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
//Here you need to call directory chooser activity.
final Intent chooserIntent = new Intent(this, DirectoryChooserActivity.class);
final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
.newDirectoryName("DirChooserSample")
.allowReadOnlyDirectory(true)
.allowNewDirectoryNameModification(true)
.build();
chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, config);
startActivityForResult(chooserIntent, REQUEST_DIRECTORY);
}
Import DirectoryChooserActivity and DirectoryChooserConfig class in your activity; If you are not able to import the mentioned class then you are not added library into the project correctly.
Related
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...
I am new to android development and just started working on a web app using cordova, ionic framework and angular. I have completed the basic features of the app and found that the transitions between views in the app are a bit slow
I found this article to improve them here:
https://github.com/ajoslin/angular-mobile-nav/wiki/PhoneGap,-improving-performance
I have never coded in java and so I am stuck.
I tried doing the following
went to the cordovawebview.java in the path myapp\platforms\android\CordovaLib\src\org\apache\cordova and added the import statements missing in the file (except for the "import org.apache.cordova.CordovaWebView")
which were using in the article and copy-pasted the myWebview class.
Then I went to the StarterApp.java, below path
\myapp\platforms\android\src\com\ionicframework\starter
and modified it to
public class StarterApp extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
CordovaWebView webView = new MyWebView(MyActivity.this);
super.init(webView, new CordovaWebViewClient(this, webView), new CordovaChromeClient(this, webView));
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html")
}
}
But when I run the cordova build command I am getting a error. Could someone tell me, what I am missing?
This looks incorrect to me:
CordovaWebView webView = new MyWebView(MyActivity.this);
Have you written code for MyWebView?
MyActivity doesn't seem to exist. You can just use this.
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'
The below code was automatically generated when I started a new android project.
I'm getting an error on the "R.layout.main" saying it does not exist.
I do in fact have a main.xml and I can see the layout change as I edit it in the Graphical Layout tab.
How can I fix this so I can run my application?
public class ComplimentGeneratorActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
The package name of the R file and the package name of your source code may not match. Make sure the package your code is in is the same as the package defined in the manifest file. Otherwise you will need to import the R file with the full package name (ex: com.example.R.layout.main).
If they match, for some reason your R file was not generated properly. Try cleaning your project.
Also, start accepting some answers. I almost didn't answer this because of your horrible acceptance rate.
This may be a very simple answer, but it has happened to me before. Try to restart eclipse. File -> Restart
Try to import the R.java file with the full path inside the main activity class file...
import com.example.packagename.R;
Hope, this will solve your query.
What I did was create two .java files. One that can compile and run on a 1.5 phone (SDK3) and then one that works on 2.0(SDK5) So for this example i'll call the 1.5 file ExampleOld and the new one Example. I was wondering if i just made activity like this if it would work sort of like a "portal" and pick the activity to load depending on the SDK so there is no crash or compile errors. Are there any changes I should make to my code? Maybe anyone out there that's had to do this before. thanks!
package com.my.app;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
public class ExamplePortal extends Activity {
int sdk=new Integer(Build.VERSION.SDK).intValue();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (sdk<5) {
Intent v = new Intent(this, ExampleOld.class);
startActivity(v);
}
else {
Intent v = new Intent(this, Example.class);
startActivity(v);
}
}
}
What you're doing (correct me if I'm wrong) is trying to maintain backwards compatibility while making use of new APIs if the user is running a newer android version. The best way to do this is to follow the tutorial Google posted here. This avoids any verification issues and is really the best way to do stuff imho.
I would put this decision in a Factory Class to avoid having these if-else statements all over the codebase.