Logcart is giving error like, on my phone
2020-05-03 17:48:38.715 1785-2071/com.example.tasteportal04b E/libGLESv2: ASUS:glGetString HOOK !!!! name=0x1f01,ret=Adreno (TM) 512
On some devices like Samsung S6, the app is not starting, displaying a crash message, on my Asus works perfectly
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tasteportal04b">
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_taste" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:name=".nootificare"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true"
android:screenOrientation="portrait"
android:hardwareAccelerated="true"
android:largeHeap="true"
>
<activity android:name=".MainActivity"
android:hardwareAccelerated="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NewActivity" android:screenOrientation="portrait"
android:theme="#style/SplashTheme"></activity>
</application>
</manifest>
NewActivity.java
package com.example.tasteportal04b;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.HapticFeedbackConstants;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.getbase.floatingactionbutton.FloatingActionButton;
import java.util.Objects;
public class NewActivity extends AppCompatActivity {
Toolbar toolbar;
private WebView webView;
private ProgressBar progressbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setTitle("TASTE Live");
toolbar.setSubtitle("v1.0");
toolbar.setLogo(R.mipmap.tasteico);
toolbar.setTitleTextColor(getResources().getColor(R.color.colortitle));
toolbar.setSubtitleTextColor(getResources().getColor(R.color.colorsubtitle));
webView = findViewById(R.id.webView);
progressbar = findViewById(R.id.progressbar);
progressbar.setMax(100);
webView.loadUrl("https://");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(false);
webView.setBackgroundColor(Color.TRANSPARENT);
webView.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int newProgress)
{
super.onProgressChanged(view, newProgress);
progressbar.setProgress(newProgress);
}
});
FloatingActionButton facebook = findViewById(R.id.Facebook);
FloatingActionButton classroom = findViewById(R.id.Classroom);
FloatingActionButton blog = findViewById(R.id.Blog);
FloatingActionButton youtube = findViewById(R.id.Youtube);
FloatingActionButton drive = findViewById(R.id.Drive);
facebook.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
try {
Intent gofb = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/"));
startActivity(gofb);
} catch(Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/TASTEATB")));
}
showToast("T.A.S.T.E Facebook");
}
});
classroom.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Intent goclass = new Intent(Intent.ACTION_VIEW, Uri.parse("https://classroom.google.com/u/0/c/NzgzMTc2MDk5NjNa"));
startActivity(goclass);
showToast("T.A.S.T.E Classroom");
}
});
blog.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Intent goblog = new Intent(Intent.ACTION_VIEW, Uri.parse("https://"));
startActivity(goblog);
showToast("T.A.S.T.E Blog");
}
});
youtube.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Intent goyt = new Intent(Intent.ACTION_VIEW);
try {
goyt.setData(Uri.parse("https://"));
goyt.setPackage("com.google.android.youtube");
} catch(Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/channel/")));
}
startActivity(goyt);
showToast("T.A.S.T.E Youtube");
}
});
drive.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
Intent godrive = new Intent(Intent.ACTION_VIEW, Uri.parse("https://"));
startActivity(godrive);
showToast("T.A.S.T.E Drive");
}
});
}//inchide oncreate
public void showToast(String message){
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main,menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId())
{
case R.id.bug:
Intent gobug = new Intent(Intent.ACTION_VIEW, Uri.parse("https://"));
startActivity(gobug);
showToast("Raporteaza un bug");
break;
case R.id.update:
showToast("Update aplicatie");
webView.loadUrl("https://");
break;
}
return super.onOptionsItemSelected(item);
}
}
Related
I've been trying to get this app to switch activities by simply clicking the button, but the app simply refreshes and I stay on the same activity. Nothing happens. And if I uncomment the lines of code for my second activity, the OnClick ones, I get null pointer errors. I have no idea what I could be doing wrong. Here's my code in main activity:
package com.example.commontaskslite;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.Button;
import android.widget.CompoundButton;
import java.util.Calendar;
public class MainActivity extends AppCompatActivity {
private TimePicker alarmClock;
private PendingIntent pendingIntent;
private AlarmManager alarmManager;
private Button search;
private Button redial;
private Button address;
boolean checked = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alarmClock = (TimePicker) findViewById(R.id.timePicker);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
ToggleButton toggle = (ToggleButton) findViewById(R.id.toggleButton);
search = (Button) findViewById(R.id.search);
redial = (Button) findViewById(R.id.redial);
address = (Button) findViewById(R.id.address);
search.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
openSearch(view);
}
});
redial.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
openRedial(view);
}
});
address.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
openShowAddress(view);
}
});
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
if(isChecked){
checked = true;
onToggleClicked();
}
else{
checked = false;
onToggleClicked();
}
}
});
}
public void openSearch(View V){
Intent _intent = new Intent(MainActivity.this,Search.class);
startActivity(_intent);
}
public void openRedial(View V){
Intent _intent = new Intent(MainActivity.this,Redial.class);
startActivity(_intent);
}
public void openShowAddress(View V){
Intent _intent = new Intent(MainActivity.this,ShowAddress.class);
startActivity(_intent);
}
public void onToggleClicked(){
long time;
if(checked) {
Toast.makeText(MainActivity.this, "ALARM ON", Toast.LENGTH_SHORT).show();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, alarmClock.getHour());
calendar.set(Calendar.MINUTE, alarmClock.getMinute());
Intent intent = new Intent(this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
time = (calendar.getTimeInMillis() - (calendar.getTimeInMillis() % 60000));
if (System.currentTimeMillis() > time) {
if (calendar.AM_PM == 0) {
time = time + (1000 * 60 * 60 * 12);
} else {
time = time + (1000 * 60 * 60 * 24);
}
}
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 10000, pendingIntent);
}
else{
alarmManager.cancel(pendingIntent);
Toast.makeText(MainActivity.this,"ALARM OFF", Toast.LENGTH_SHORT).show();
AlarmReceiver.ringtone.stop();
}
}
}
Here's the code in the second activity:
package com.example.commontaskslite;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Build;
import android.os.Bundle;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;
public class Search extends AppCompatActivity {
private PendingIntent pendingIntent;
private Button alarm;
private Button redial;
private Button address;
private SearchView searchView;
private String searchQuery;
private Intent intent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
intent = getIntent();/*
address = (Button) findViewById(R.id.address2);
redial = (Button) findViewById(R.id.redial2);
alarm = (Button) findViewById(R.id.alarm);
searchView = (SearchView) findViewById(R.id.searchView);
searchView.setOnQueryTextListener(new OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String s) {
searchQuery = s;
return true;
}
#Override
public boolean onQueryTextChange(String s) {
return false;
}
});
address.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
openShowAddress(view);
}
});
redial.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
openRedial(view);
}
});
alarm.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
openMainActivity(view);
}
});*/
}
public void openShowAddress(View V){
Intent _intent = new Intent(this,ShowAddress.class);
startActivity(_intent);
}
public void openRedial(View V){
Intent _intent = new Intent(this,Redial.class);
startActivity(_intent);
}
public void openMainActivity(View V){
Intent _intent = new Intent(this,MainActivity.class);
startActivity(_intent);
}
}
And here's the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.commontaskslite">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.CommonTasksLite">
<activity
android:name=".ShowAddress"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.ALL_APPS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".Redial"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.CALL"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".Search"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".AlarmReceiver">
</receiver>
</application>
</manifest>
summarizing the answer that was found in comments.
Change setContentView(R.layout.activity_main); to another layout other than activity_main in Search Activity.
When I tried to access (file:///sdcard/) using mobile browsers (ex. Firefox, Opera ..etc). It shows me an index page for the SDCard (see the screenshot).
However, when I access the same url using a webview and give it a storage permission and does not show the Index page. My code is below:
package com.example.webbrowser;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Toast;
import java.io.IOException;
import android.content.Context;
import android.net.ConnectivityManager;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
class NetworkState {
public static boolean connectionAvailable(Context context){
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
return connectivityManager.getActiveNetworkInfo() !=null;
}
}
class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
CookieManager.getInstance().setAcceptCookie(true);
return true;
}
}
public class MainActivity extends AppCompatActivity {
WebView webView;
EditText editText;
ProgressBar progressBar;
Button back, forward, stop, refresh, homeButton;
Button goButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.web_address_edit_text);
back = (Button) findViewById(R.id.back_arrow);
forward = (Button) findViewById(R.id.forward_arrow);
stop = (Button) findViewById(R.id.stop);
goButton = (Button)findViewById(R.id.go_button);
refresh = (Button) findViewById(R.id.refresh);
homeButton = (Button) findViewById(R.id.home);
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
progressBar.setMax(100);
progressBar.setVisibility(View.VISIBLE);
webView = (WebView) findViewById(R.id.web_view);
if (savedInstanceState != null) {
webView.restoreState(savedInstanceState);
} else {
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setSupportMultipleWindows(true);
webView.getSettings().setAllowContentAccess(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.setBackgroundColor(Color.WHITE);
webView.setWebChromeClient(new WebChromeClient() {
#Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
progressBar.setProgress(newProgress);
if (newProgress < 100 && progressBar.getVisibility() == ProgressBar.GONE) {
progressBar.setVisibility(ProgressBar.VISIBLE);
}
if (newProgress == 100) {
progressBar.setVisibility(ProgressBar.GONE);
}else{
progressBar.setVisibility(ProgressBar.VISIBLE);
}
}
});
}
}
public void go_button(View view) {
try {
if(!NetworkState.connectionAvailable(MainActivity.this)){
Toast.makeText(MainActivity.this, "Check connection", Toast.LENGTH_SHORT).show();
}else {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(), 0);
webView.loadUrl(editText.getText().toString());
editText.setText("");
}
}catch (Exception e) {
e.printStackTrace();
}
}
public void home_button(View view) {
webView.loadUrl("https://google.com");
}
public void refresh_button(View view) {
webView.reload();
}
public void stop_button(View view) {
webView.stopLoading();
}
public void forward_button(View view) {
if (webView.canGoForward()) {
webView.goForward();
}
}
public void back_button(View view) {
if (webView.canGoBack()) {
webView.goBack();
}
}
}
Android mainifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.webbrowser">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.WebBrowser">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Any help ?
package com.example.intent;
import androidx.annotation.Nullable;
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.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText etEnterName;
Button btnActivity2;
Button btnActivity3;
TextView tvMessage;
final int ACTIVITY3=3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etEnterName=findViewById(R.id.etEnterName);
btnActivity2=findViewById(R.id.btnActivity2);
btnActivity3=findViewById(R.id.btnActivity3);
btnActivity2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (etEnterName.getText().toString().isEmpty()) {
Toast.makeText(MainActivity.this, "please enter all fields", Toast.LENGTH_SHORT).show();
}
else {
String name = etEnterName.getText().toString().trim();
Intent intent = new Intent(MainActivity.this,
com.example.intent.Activity2.class);
intent.putExtra("name",name);
startActivity(intent);
}
}
});
btnActivity3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,
com.example.intent.Activity3.class);
startActivityForResult(intent,ACTIVITY3);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==ACTIVITY3)
{
if (resultCode==RESULT_OK){
tvMessage.setText(data.getStringExtra("surname"));
}
if(resultCode==RESULT_CANCELED){
tvMessage.setText("no data received");
}
}
}
}
3rd Activity
package com.example.intent;
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 Activity3 extends AppCompatActivity {
Button btnSubmit;
EditText etSurname;
Button btnCancel;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_3);
btnSubmit=findViewById(R.id.btnSubmit);
etSurname=findViewById(R.id.etSurname);
btnCancel=findViewById(R.id.btnCancel);
btnSubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(etSurname.getText().toString().isEmpty()){
Toast.makeText(Activity3.this,"please enter your surname" Toast.LENGTH_SHORT).show();
}
else {
String surname = etSurname.getText().toString().trim();
Intent intent = new Intent();
intent.putExtra("surname",surname);
setResult(RESULT_OK,intent);
Activity3.this.finish();
}
}
});
btnCancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setResult(RESULT_CANCELED);
Activity3.this.finish();
}
});
}
}
This is the manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intent">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Activity3"></activity>
<activity android:name=".Activity2" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Explanation
Blockquote
I following a youtube video and i cant find where i am getting the whole thing wrong. The button main activity works perfectly fine and take me to the third intent but when i enter data in edit text box and click the submit button the app crashes.
I had not added this line of code.
tvMessage = findviewbyid (R.id.tvMessage);
My bad –
Hello my App crash if I try to open my AddIP.class fragment
My error code says:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{de.kwietzorek.fulcrumwebview/de.kwietzorek.fulcrumwebview.MainActivity$AddIP}: java.lang.InstantiationException: java.lang.Class has no zero argument constructor
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.kwietzorek.fulcrumwebview" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true">
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity$AddIP"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
MainActivity.java
package de.kwietzorek.fulcrumwebview;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import java.util.ArrayList;
public class MainActivity extends FragmentActivity {
String selected;
Spinner spinner;
WebView myWebView;
ArrayList<String> server_name_list = null;
/* Menu */
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.add_server:
Intent intent = new Intent(this, AddIP.class);
this.startActivity(intent);
return true;
case R.id.menu_refresh:
myWebView.reload();
return true;
default:
return true;
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//WebView
myWebView = (WebView) findViewById(R.id.webView);
myWebView.setWebViewClient(new WebC());
WebSettings webSettings = myWebView.getSettings();
//JavaScript enable
webSettings.setJavaScriptEnabled(true);
//Server name spinner
if (server_name_list != null) {
spinner = (Spinner) findViewById(R.id.server_spinner);
ArrayAdapter<String> server_adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, server_name_list);
server_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(server_adapter);
server_adapter.notifyDataSetChanged();
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
selected = parent.getItemAtPosition(pos).toString();
myWebView.loadUrl(selected);
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
//WebView Client
public class WebC extends WebViewClient {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
}
public class AddIP extends Fragment {
Button btn_back, btn_add;
EditText server_ip, server_name;
String new_server_ip, new_server_name;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_ip);
server_ip = (EditText) findViewById(R.id.edit_server_address);
server_name = (EditText) findViewById(R.id.edit_server_name);
/* Back Button */
btn_back = (Button) findViewById(R.id.btn_back);
btn_back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
});
/* Add IP Button */
btn_add = (Button) findViewById(R.id.btn_add);
btn_add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
/*new_server_ip = server_ip.getText().toString();
MainActivity.server_array_ip.add(new_server_ip);*/
new_server_name = server_name.getText().toString();
server_name_list.add(new_server_name);
}
});
}
}
}
Add this method to your faragment :
public AddIP() {
}
in some situation you need an empty constructor method for your fragment
As above. I'm to sure what I'm doing wrong. Here is the code for the MainActivity.java and the code for the NoteMain.java When I click on the Notes button on the home screen when the app loads it says Unfortunately,(app name) has stopped.
I don't know why? Any help is appreciated.
Thanks in advance
MainActivity:
package com.qub.buildersbuddy;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Button buttonConverter;
Button buttonCalculator;
Button buttonNotePad;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button ConvertBtn = (Button) findViewById(R.id.butonConverter);
ConvertBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,CentInch.class);
startActivity(intent);
}
});
Button CalcBtn = (Button) findViewById(R.id.buttonCalc);
CalcBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,Calculator.class);
startActivity(intent);
}
});
Button NoteBtn = (Button) findViewById(R.id.buttonNotes);
NoteBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,NoteMain.class);
startActivity(intent);
}
});
}
public void setupConverterButton(){
buttonConverter = (Button) findViewById(R.id.butonConverter);
// Button messageButton = (Button) findViewById(R.id.butonConverter);
}
public void CentToInch(){
buttonConverter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//opening the
try{
Class centClass = Class
.forName("com.qub.buildersbuddy.CentInch");
Intent myintent = new Intent(MainActivity.this,centClass);
startActivity(myintent);
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
});
}
public void setupCalculatorButton(){
buttonCalculator = (Button) findViewById(R.id.buttonCalc);
// Button messageButton = (Button) findViewById(R.id.butonConverter);
}
public void Calculator(){
buttonCalculator.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//opening the
try{
Class calcClass = Class
.forName("com.qub.buildersbuddy.Calculator");
Intent myintent = new Intent(MainActivity.this,calcClass);
startActivity(myintent);
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
});
}
public void setupNotesButton(){
buttonNotePad = (Button) findViewById(R.id.buttonNotes);
// Button messageButton = (Button) findViewById(R.id.butonConverter);
}
public void Notes(){
buttonNotePad.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//opening the
try{
Class NoteMain = Class
.forName("com.qub.buildersbuddy.NoteMain");
Intent myintent = new Intent(MainActivity.this,NoteMain);
startActivity(myintent);
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
});
}
}
NoteMain
package com.qub.buildersbuddy;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
public class NoteMain extends Activity implements OnItemClickListener, OnClickListener {
private SharedPreferences spNotes;
private ArrayList<Note> notes;
private Button addNote;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_main);
this.addNote = (Button) findViewById(R.id.addNoteButton);
this.addNote.setOnClickListener(this);
spNotes = getSharedPreferences("notes", Context.MODE_PRIVATE);
}
#Override
protected void onResume() {
super.onResume();
showNotes();
ListView list = (ListView) findViewById(R.id.listNotes);
CustomAdapter aa = new CustomAdapter(this, getLayoutInflater(), this.notes, spNotes);
list.setAdapter(aa);
list.setOnItemClickListener(this);
}
private void showNotes() {
this.notes = new ArrayList<Note>();
Map map = spNotes.getAll();
for (Object o : map.entrySet()) {
Entry e = (Entry<String, String>) o;
this.notes.add(new Note((String)e.getKey(), (String)e.getValue()));
}
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
Intent intent = new Intent(this, NoteActivity.class);
intent.putExtra("title", this.notes.get(position).getTitle());
intent.putExtra("text", this.notes.get(position).getText());
startActivity(intent);
}
#Override
public void onClick(View arg0) {
Intent intent = new Intent(this, NoteActivity.class);
startActivity(intent);
}
}
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.qub.buildersbuddy"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.qub.buildersbuddy.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.qub.buildersbuddy.CentInch"
android:label="#string/title_activity_cent_inch" >
</activity>
<activity
android:name="com.qub.buildersbuddy.Calculator"
android:label="#string/title_activity_calculator" >
</activity>
<activity
android:name="com.qub.buildersbuddy.NotePad"
android:label="#string/title_activity_note" >
</activity>
</application>
</manifest>
Its probably because you don't have the NoteMain activity defined in your Manifest.
<activity
android:name="com.qub.buildersbuddy.NoteMain"
android:label="#string/title_activity_note" >
</activity>