So, this app is for my class library, but whenever I click login in the 1st activity after putting in my details, the app crashes. Please look at this issue.
My 1st Main activity code:
package com.cls2r.library;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText login_text, password_text;
Button login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login_text = (EditText) findViewById(R.id.login);
password_text = (EditText) findViewById(R.id.password);
login = (Button) findViewById(R.id.button_login);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = login_text.getText().toString();
String password = password_text.getText().toString();
if(username.equals("admin") && (password.equals("123456")))
{
Toast.makeText(MainActivity.this, "Welcome Soham", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(getApplicationContext(),MainActivit2y.class);
startActivity(intent);
}else
{
Toast.makeText(MainActivity.this, "Welcome Guest", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(getApplicationContext(),MainActivit2y.class);
startActivity(intent);
}
}
});
}
}
Other MainActivity code:
package com.cls2r.library;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
public class MainActivit2y extends AppCompatActivity {
private AdView mAdView;
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main1);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(@NonNull InitializationStatus initializationStatus) {
}
});
mAdView = findViewById(R.id.adView);
AdRequest adRequest= new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
webView=(WebView) findViewById(R.id.web_view);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://sites.google.com/view/cls2rlibraryybis/home");
WebSettings webSettings=webView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
public class mywebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view,url,favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public void onBackPressed() {
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
}
Please try to resolve this issue. I built the app to a signed APK file and deployed it on my device for testing, and the app kept on crashing after I clicked the login button. I thought it would open the next activity, but no. Please check for my mistake...
There are many factors causing crash of an activity. However, here are some general factors.
android:exported
attribute.AppCompatActivity
, the activity might not apply AppCompat
theme.To inspect more accurately, please provide the error message.