Android studio does not show any Logs I wrote in my code. I have tried putting the log to verbose and debug. I am using 'No filters'. Why is 'Oncreatetestlog' not showing up in my logcat?
package com.example.keydown;
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) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState != null) {
Log.d("Oncreatetestlog", "onCreate() Restoring previous state");
/* restore state */
} else {
Log.d("Oncreatetestlog2", "onCreate() No saved state available");
/* initialize app */
}
}
}
Go to File -> invalidate caches / Restart. And let Android Studio index your project again. It works for me.
After hours of searching and trying, I found out it did not have to do with Android Studio, but that my phone didn't allow Logging. See this answer for more information.
Alternatively, you could use System.out.println() to show the text in logcat
Replace
Log.d("Oncreatetestlog", "onCreate() Restoring previous state");
With
System.out.println("Oncreatetestlog onCreate() Restoring previous state");
If Log.d is not showing in your Logcat just replace Log.d with Log.wtf Like this:
Replace:
Log.d("tag",""+catstr);
With:
Log.wtf("tag",""+catstr);
It Works..happy coding;)
Please check in "Run" on the right side of "Debug" on the bottom of the IDE.
in my case i actually did everything what they told but yet it's not working. so i checked there and i fount all the log over there.
thanks
Related
I am working on my first app in Android Studio and have created a button "buttonFish" in the xml creator that I now want to put an action onto in the mainactivity.java.
This is my code:
package com.example.acfaunapedia;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
Private Button butf;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
butF = (Button) findViewById(R.id.buttonFish);
}
}
It can find my Button but it doesnt recognize the Type "Button".
Any ideas on how to fix this?
Error Message Link
EDIT:
I created an empty activity to start with, but I don't think thats relevant.
Alt-Enter is your friend. This Android Studio shortcut key will prompt you for solution(s) to error messages.
In this case, it will probably prompt you to add import android.widget.Button in your source, which should resolve the problem.
ALSO:
In the future, please copy/paste the error message text into your post. "Text" is generally more helpful than "screenshots" ;)
Here's the error (from your screenshot):
public class MainActivity extends AppCompatActivity {
Private Button butf; // <-- Cannot resolve symbol 'butf'
As nanofarad pointed out, the problem isn't "Buttom" per se (although that IS a problem), it's that you said "Private" instead of keyword private.
Alt-Enter should help with ANY error.
And once again: "Generally, text is better than screenshots"
I have a WebView that loads this WebSite
If you try to put an identification and click out of the box, it shows a little loading and tells if the identification is correct it shows a virtual keyboard within the site, not a device keyboard, if its incorrect it shows a error message, like this
Site showing error
However, if i put the same website on my WebView, it loads the site perfectly, but it won't execute these commands, if i put any identification and click out it doesn't shows the loading, it won't do anything.
Funny part is, if i do the same WebView in Xcode for iPhone, it does everything normally, even the commands, it checks for the identification, etc...
What i've tried
Turning on/off:
Javascript
Plugins(even deprecated)
My code:
package com.example.viskee.webview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wbAba = (WebView) findViewById(R.id.wbAba);
wbAba.setWebViewClient(new WebViewClient());
wbAba.getSettings().setJavaScriptEnabled(true);
wbAba.loadUrl("https://ib.rendimento.com.br");
}
}
EDIT:
If i use
wbAba.setChromeClient(new ChromeClient);
it works fine, however i don't want to use ChromeClient because it adds an address bar, etc... I want my WebView to be FullScreen, show only the website
Have you try this:
WebView wbAba = (WebView) findViewById(R.id.wbAba);
wbAba.setWebViewClient(new WebViewClient());
wbAba.getSettings().setUseWideViewPort(true);
wbAba.getSettings().setLoadWithOverviewMode(true);
wbAba.getSettings().setJavaScriptEnabled(true);
wbAba.loadUrl("https://ib.rendimento.com.br");
and one final thing, don't forget to set internet permission on manifest.xml file:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Let me know, if this doesn't work.
I found a solution, all i had to do was:
wbAba.getSettings().setDomStorageEnable(true);
Cannot resolve symbol findViewById(), getApplicationContext(), and many more basic functions, maybe I did something wrong with the Resources file, but I don't know what to do now to correct.
package com.example.apple.onlinesql;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class Answer extends AppCompatActivity {
TextView questionTextView, answerTextView;
String question, answer;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_answer);
Bundle bundle = getIntent().getExtras();
question = bundle.getString("question");
answer = bundle.getString("answer");
/*cannot resolve symbol findViewById()*/
questionTextView = (TextView) findViewById(R.id.questionTextView);
answerTextView = (TextView) findViewById(R.id.answerTextView);
questionTextView.setText(question);
answerTextView.setText(answer);
}
}
The application hasn't build successfully, as #vasilis mentioned try to clean and rebuild your project. And if that not solve the case, restart your studio and in worst case restart you system.
You appear to be running into the corrupt cache bug in Android Studio.
To fix: File > Invalidate Caches / Restart
I got the way although not very efficient but I got the way. I copied my entire project to a different location and opened it from there. MAGIC it worked for me.
When turn the switch on it stays on.. however when i leave the activity and come back to it.. it goes back to off. I want it to stay ON OR OFF depending on whats last pressed. I have tried the code below but does not resolve my issue
SwitchButton.setChecked(true);
SwitchButton.setChecked(false);
What you need to do is override these methods in your activity:
#Override
protected void onSaveInstanceState (Bundle outState){
super.onSaveInstanceState(outState);
outState.putBoolean("CHECKED", SwitchButton.isChecked());
}
then in onCreate:
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstaceState);
if(savedInstanceState != null){
boolean isChecked = savedInstanceState.getBoolean("CHECKED");
SwitchButton.setChecked(isChecked);
}
}
If you are minimizing the activity and then returning back to it, and you want all controls to retain their states, then look into implementing saved instance state. This will persist the control values while you minimize / maximize the activity or rotate it. No data is permanently saved to the device. Sample code here:
http://developer.android.com/training/basics/activity-lifecycle/recreating.html#SaveState
If you are closing the app completely and want the app to remember the settings, then consider SharedPreferences, which can be used to save data locally on the device. The data persists until your app explicitly deletes it or you uninstall the app. Sample code here:
http://developer.android.com/training/basics/data-storage/shared-preferences.html
I want to see any variable (String var) value in my android program.
You can say for debugging purpose.
When I am printing anything using, say System.out.print("Hello")
Then I am unable find this output any where.
Do anyone have idea where to find this output.
Here is my code-
package com.test1.nus;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.print("Hello");
....
}
By default, the Android system redirects stdout (System.out) output to /dev/null, which means your messages are lost.
Instead, the common pattern to log debug strings in Android is the following
import android.util.Log;
Then at the top of your class YourClass
private static final String TAG = YourClass.class.getSimpleName();
And to log debug strings you need to call
Log.d(TAG, "your debug text here");
which in your case results in
package com.test1.nus;
import android.util.Log;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "Hello");
....
}
Finally you can see your debug strings in Eclipse via
Windows > Show view > Other and select LogCat
and if required filter by the tag of YourClass.
However, if you really need to see messages written by System.out.println you need to tell Android to route them to logcat via the following shell commands
$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start
and then you will be able to see your debug messages in Eclipse via LogCat view and the tag stdout.
You can get more details from the official documentation here http://developer.android.com/tools/debugging/debugging-log.html
Your output will be logged to logcat
Assuming you are using eclipse:
Window > Show View ---> Logcat (If this not visible, select other--Android--Logcat)
See this link: http://www.droidnova.com/debugging-in-android-using-eclipse,541.html
It will show some screen shots related to logcat. There you can find out your output message.
Follow this: http://developer.android.com/tools/help/logcat.html
If you want to check your output in the android emulator use Toast messages.
The result with system.out.println("....") will be displayed in logcat.
To check in android emulator/device.just do like this
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_LONG).show();
I suggest you take a look at the android.util.log class. The Android developer pages has a good introduction for using it. (In fact, I just found this today since I'm learning Android programming myself.)
If you use the AVD s that will give you a more interesting experience than just print in the log. Here they have described all those things perfectly.
You are better off using Logs if it is for debugging purposes.
There are various methods available like Log.v() Log.d() Log.i() Log.w() and Log.e() for verbose, debug, info, warn and error logs respectively.
Then you can check the logcat while debugging the application.
For further reference, go here.