import android.support.v7.app.AppCompatActivity; - java

I've created a new project in android studio 3.3.2 it isn't recognizing appCompat and onCreate method which comes as default in creation of main activity
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
should have recognized onCreate and appCompat

Goto File -> Invalidate Caches and Restart.

Try to reinstall the whole IDE along with caches

Related

The monitor of Android Studio do not show Logs

the monitor of Android Studio do not show Logs.
I have the code:
package com.nv.threadpassdata;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import android.content.Context;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "START";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG, "Start");
}
}
And the monitor shows NOTHING:
In settings the Log ticks are ON.
I do not use emulator. Instead of emulator I connect my Phone (HUAWEI MYA-L41)
What is the problem? Can anybody find?
Thanks,
Nickolas
Try to do on of the following:
File>Invalidate Caches and Restart
Build>Clean Project then Build>Rebuild Project

Android: Overriding onCreate method of main activity

I have a Java activity like so.
package com.xxx.yyy.overrideoncreate;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("DEBUG","Original oncreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I wish to split some of the onCreate instructions to a separate class, so I created this too.
package com.xxx.yyy.overrideoncreate;
import android.os.Bundle;
import android.util.Log;
/**
* Created by oox on 26/6/17.
*/
public class SubClass extends MainActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("DEBUG","Overridden");
super.onCreate(savedInstanceState);
}
}
I intend for subClass.onCreate to override MainActivity.onCreate -- both Overridden and original oncreate messages should be displayed. However, that did not seem to happen, the overridden message did not appear in the Logcat.
Any idea what I did wrong?
Thanks in advance.
In order for SubClass's onCreate to be called, an instance of SubClass should be created instead of an instance of MainActivity when the application is launched.
For that to happen, SubClass should become the actual main activity of your application (i.e. the activity class registered in the AndroidManifest.xml which gets launched when the application is launched).

java.lang.ExceptionInIntilizerError in main

My app crashes straight away with an exception
Here is the code of my main activity
package com.example.orientation;
import android.os.Bundle;
import android.app.FragmentManager;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
public class MainActivity extends ActionBarActivity implements myList.Communication {
myList listFragment;
Details detailsFragment;
FragmentManager manager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
manager=getFragmentManager();
listFragment = (myList) manager.findFragmentById(R.id.listFragment);
listFragment.setCommunicator(this);
}
#Override
public void respond(int index) {
detailsFragment = (Details) manager.findFragmentById(R.id.detailFragment);
if (detailsFragment!=null && detailsFragment.isVisible()) {
detailsFragment.changeData(index);
}else{
Intent intent = new Intent(this,DetailActity.class);
intent.putExtra("index",index);
startActivity(intent);
}
}
}
I tried reading documentation but could not get how to solve this. Any help will be appreciated. Thank You.
If you have only added android support jar, you must add the whole Appcompat project to your workspace:
right click -> IMport -> Android -> Project from Existing Source
Then go to SDK Folder where you installed and find extras/android/support/v7/appcompat
and add this whole Library.
It seems like you are missing resources needed for ActionBarActivity

unfortunately, parseStarterProject has stopped work

ParseApplication firstly adding keys to ParseApplication.java is good but after sdk test show error in device "unfortunately, parseStarterProject has stopped work"
this is my ParseApplication.java file
package com.parse.starter;
import android.app.Application;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseCrashReporting;
import com.parse.ParseObject;
import com.parse.ParseUser;
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Initialize Crash Reporting.
ParseCrashReporting.enable(this);
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Add your initialization code here
//copy and paste frome parse.com
// Parse.initialize(this, YOUR_APPLICATION_ID, YOUR_CLIENT_KEY);
Parse.initialize(this, "oaXYWiKShMVJ0VqZ52zwVnzpNlC3CKEReLV5wANX", "BiHRJalzAGYgFmh250SDxBxxi8DaIdnsnfunBfpC");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// Optionally enable public read access.
// defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
ParseObject testObject = new ParseObject("TestObject");
testObject.put("foo", "bar");
testObject.saveInBackground();
}
}
Another, ParseStarterProjectActivity.java file is
package com.parse.starter;
import android.app.Activity;
import android.os.Bundle;
import com.parse.ParseAnalytics;
public class ParseStarterProjectActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ParseAnalytics.trackAppOpenedInBackground(getIntent());
}
}
this is doing in android studio and it's a starting project of parse.com "get start project"
if you are using android studio as a working environment....then what you just need is exit the android studio and then again open it and run your project it solve my problem......I think your will also help likewise.
Remove ParseUser.enableAutomaticUser(); from your code then try again?

tried exporting my app the process failed and ended up giving me errors in my code

hey i am new to android development. i tried exporting my app the process failed because of some minor errors and then i got errors all over my code. it was working perfectly fine with no errors before attempting to export.
check these two pics of the xml files where the errors popped up
main activity file: http://postimg.org/image/4gwdipnap/
second activity file: http://postimg.org/image/vuy1ryba3/
I didn't have any of these errors before trying to export the project.
heres the code for both of the files
main activity page
package youngadults.camden;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
public class FrontPage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.front_page);
findViewById(R.id.uyounadults).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(FrontPage.this, youngadultsp.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
}
});
}
}
second activity page
package youngadults.camden;
import android.app.Activity;
import android.os.Bundle;
public class youngadultsp extends Activity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.youngadultsp_1);
}
}
You need to set Android API level, do you use Android Studio or Eclipse?
For Eclipse edit your Manifest file (19 is example):
<uses-sdk android:minSdkVersion="19" />
For Android Studio
Right click the App directory
Select "Open Module Setting" at the bottom
Under Modules select app
Set 'Compile Sdk version' as you want

Categories