Android crashes whenever this activity is started. here is the code.
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class SettingsActivity extends Activity {
EditText vname, vphone, vemail, vaddress;
TextView textDeviceID;
Button settings_submit;
#Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.settingmenu);
vname = (EditText) findViewById(R.id.get_name);
vphone = (EditText) findViewById(R.id.get_phone);
vemail = (EditText) findViewById(R.id.get_email);
vaddress = (EditText) findViewById(R.id.get_address);
settings_submit = (Button) findViewById(R.id.settings_submit);
settings_submit.setOnClickListener(settings_submitOnClickListener);
TextView textDeviceID = (TextView) findViewById(R.id.deviceid);
super.onCreate(savedInstanceState);
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(
you should tell us more details. But I see that everything looks fine, except that
super.onCreate(savedInstanceState);
should go before setContentView() and all other stuff. By the way, check your xml for bad config controls too.
Related
i want to show my post in webview but i fatch error of "Inconvertible type cannot cast android.view.view to javafx.scene.web.webview" in android studio.
how can i solve it please help me.
WPPostDetails.java
package com.ejobbox.ejobbox;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import javafx.scene.web.WebView;
public class WPPostDetails extends AppCompatActivity {
TextView title;
WebView webView;
#Override
public void onCreate(#Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_postdetails);
title=(TextView) findViewById(R.id.title);
webView= (WebView) findViewById(R.id.postwebview);
Intent i = getIntent();
int position = i.getExtras().getInt("itemPosition");
//title.setText(MainActivity.mListPost.get(position).getTitle().getRendered());
Log.e("WpPostDetails","title is"+MainActivity.mListPost.get(position).getTitle().getRendered());
webView.getSettings().setJavaScriptEnabled(true);
}
}
You import a wrong WebView class. Remove import javafx.scene.web.WebView; and add import android.webkit.WebView
Import
android.webkit.WebView instead of
javafx.scene.web.WebView;
I was watching a youtube tutorial (Firebase storage and around 14 minutes I got this error code:
Cannot resolve method 'getInstance()'
Can someone help me resolve it? I am pretty new to Java and have been watch tutorials to get the understanding right. I know this is a small detail, but it has been really frustrating.
package bfb.ess.myapplicationbfb;
import android.app.ProgressDialog;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.storage.UploadTask;
import java.io.File;
import java.io.IOException;
public class speakp extends AppCompatActivity {
private Button mRecordBtn;
private TextView mRecordlabel;
private MediaRecorder mRecorder;
private String mFileName = null;
private static final String LOG_TAG = "Record_log";
private StorageReference mStorage;
private ProgressDialog mProgress;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recordpage);
mStorage = FirebaseStorage.getInstance().getReference(); /*RIGHT HERE*/
mRecordlabel = (TextView) findViewById(R.id.recordlabel);
mRecordBtn =(Button) findViewById(R.id.recordBtn);
This is the code and the error in "Cannot resolve symbol 'message'" on the line:
EditText editText = (EditText) findViewById(R.id.message);
The application worked well, previously. It's likely to be a stupid error.
File MainActivity.java
package com.example.antonio.newsbooklite2;
/**
* Created by antonio on 30/12/16.
*/
import android.os.Bundle;
import android.support.annotation.Nullable;
//import android.support.design.widget.*;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.*;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import java.util.ArrayList;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/** Called when the user clicks the Send button */
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
// Do something in response to button
}
}
File strings.xml
<resources>
<string name="app_name">newsbooklite2</string>
<string name="message">Scrivi messaggio: </string>
<string name="button_send">Send</string>
enter code here
<string name="nome_stringa">Testo_visualizzato</string>
</resources>
You might be mixing these things.
findViewById(R.id.message);
returns the View from the layout.
If you want the string, you can use:
getResources().getString(R.string.message);
You are using a message id defined in the string.xml file in line:
EditText editText = (EditText) findViewById(R.id.message);
Change the message to the id defined in the layout file.
I'm a total noob at android studio, and I have a (to me) weird problem. I have inserted a button in my XML document:
<Button
android:layout_width="match_parent"
android:layout_height="127dp"
android:text="SUM"
android:id="#+id/button"
android:layout_row="15"
android:layout_column="0" />
And in the java code I would like a to make it do something when i click on it. However in code (I know there is way too many import):
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;
public class TestActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
R.id.button.onCliclistener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent action) {
DO THIS WHEN CLICKED ON
}
});
}
BUT it says: Cannot resolve method() and Cannot resolve symbol, to the onCliclistener and ActionListener. And it says: unused import statement, to thier imports. It's probably a stupid question, but what am I doing wrong?
Nicolaj
Try making reference to your button in your onCreate method and then create an onClick method.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;
public class TestActivity extends AppCompatActivity implements View.OnClickListener {
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
btn = (Button) findViewById(R.id.button); //Reference to the button
btn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
DO THIS WHEN CLICKED ON
}
}
I expect it will be helpful for you!
I'm facing problem with initLoader() while using Loader. Its not taking the third argument null. Can any one help me to fix the error?
ERROR MESSAGE:: The method initLoader(int, Bundle,
LoaderManager.LoaderCallbacks<D>) in the type LoaderManager is not
applicable for the arguments (int, null, TestActivity)
And this is my code.
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import utilcontentprovider.F1DatabaseMetaData.TeacherTableMetaData;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
public class TestActivity extends SherlockActivity
implements LoaderCallbacks<Cursor>{
ListView listView;
ArrayList<String> listName = new ArrayList<String>();
ArrayList<String> listId = new ArrayList<String>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
listView = (ListView) findViewById(R.id.list);
getLoaderManager().initLoader(0, null, this);
}
}
your imports refer to the support package so you should use getSupportLoadManager() instead of getLoaderManager().
Change
getLoaderManager().initLoader(0, null, this);
with
getSupportLoaderManager().initLoader(0, null, this);