Just update ADT and Unable to resolve superclass errer appear - java

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'

Related

How do I resolve a Redeclaration Error in Android Studio

This code is for a button that would be on the android emulator. However, when I place this code in the main activity.kt it gives me multiple errors. The first error I experience is a redeclaration error on line 9 on the main activity
package com.example.android.justjava
import android.R
import android.os.Bundle
import android.support.v7.app.ActionBarActivity
import android.view.View
import android.widget.TextView
// This activity displays an order form to order coffee.
class MainActivity : ActionBarActivity() {
protected fun onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
// this method is called when the order button is clicked.
fun submitOrder(view: View) {
display(1)
}
// This method displays the given quantity value on the screen.
private fun display(number: Int) {
val quantityTextView = findViewById(R.id.quantity_text_view as TextView
quantityTextView.text = "" + number
}
}
This activity displays an order form to order coffee.
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// This method is called when the order button is clicked.
public void submitOrder(View view) {
display(1);
}
// This method displays the given quantity value on the screen.
private void display(int number) {
TextView quantityTextView =(TextView) findViewById (R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
File tab -> Invalidate Caches/Restart (then choose invalidate and restart from the dialog that will appear)
Build tab -> Clean Project
Build tab -> Rebuild Project
This solution is just the same as #Ehsan_Haghdoust solution but letting Android Studio do that for me instead of doing that my self.
The question is for 6 months ago, but I write my answer for others face this problem in the future. I have had challenge with this error, I checked every possible way suggested by others and I FINALLY had to delete build folders in
projectFolder/
and
projectFolder/app/
manually and rebuild the project again.
The problem you face is that you have 2 activities with the same name MainActivity - one in Java, and second in Koltin. Both classes (activities in this case) are compiled into the same application - you have 2 symbols with the same name.
yes, Koltin and Java look the same after the compiler finish with them :)
In my case, I was running the app in debug mode and a direction class was generated for debug. Then I tried generating a signed APK in release mode. Then a similar class was generated in same package for release mode which caused the issue. I manually deleted just the debug folder in the Java folder(root) and the build was successful.
Build -> Select Build Variant. It was in debug, I just changed it to release mode and done.

Android Unable to Import Library project

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.

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...

Custom webview in cordova app

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.

Main layout not recognized, immediately after starting new Android project

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.

Categories