id cannot be resolved or is not a field again - eclipse

Ok this is the code in my single java file:
package text.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
public class TexttestActivity extends Activity {
/** Called when the activity is first created. */
Button btn;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
EditText piaf=(EditText)findViewById(R.id.fieldd);
piaf.setText("Inception" + "The lord of the Rings");
}
}
I keep getting that error! WTF is wrong?! i tried to google for an answer but nothing worked!

should
EditText piaf=(EditText)findViewById(R.id.fieldd);
be
EditText piaf=(EditText)findViewById(R.id.field);
??

Related

Passing User input from mainactivity to a second activity in eclipse

I am bran new to this but I have successfully created a functional button.
I am attempting to pass user input (editText1 on activity_main) to Recipe (my second activity) The first code is my functional button. What am I doing wrong in the second round of code in my attempt at passing information to be displayed on the second activity layout?
package com.example.andrew;
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;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b=(Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v){
startActivity(new Intent(MainActivity.this, Recipe.class));
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Second round of code: My attempt at passing information. First activity
package com.example.andrew;
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;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Edit Text et = (Edit Text) findViewById(R.id.editText1);
String theText = et.getText().toString();
Intent i = new Intent(this, Recipe.class);//Recipe is my second class
i.putExtra("text_label", theText);//what is "text_label"? Where should it be?
Button b=(Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v){
startActivity(new Intent(MainActivity.this, Recipe.class));
}
});
}
}
And in my second activity I have:
public class Recipe extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recipe_layout);
Intent i = getIntent();
uriStringi = i.getStringExtra("text_label");//is text_label on actv. 1?
startActivity(i);
}
You are adding data in the intent but while starting the activity you are not using it. Instead creating new intent.
Solution:
In your current Activity, create a new Intent:
Intent i = new Intent(this, Recipe.class);
i.putExtra("text_label", theText);
startActivity(i); // Write this in onClick()
Then in the Recipe, retrieve those values:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("text_label");
}

Unfortunately newsample4 stopped in android

1-When i run it,emulator does not allow to show my button.
2-this is my code:
package fatemi.prj.newsample4;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import java.util.Date;
public class MainActivity extends Activity { /*main activity*/
Button btn=new Button(this);
private OnClickListener btnOnclickListener= new OnClickListener() {
public void onClick(View v) { /* click button for showing date*/
updateTime();
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn.setOnClickListener(btnOnclickListener);
updateTime();
setContentView(btn);
}
private void updateTime() { /* defne update function*/
btn.setText(new Date().toString());
}
}

Implement existing Activity(within there extends/implements) in Fragments (Sherlock)

I have developed an app with some activities. Now I would implenent a Navigation with fragments and Sherlock.
I found a lot of examples, but I don't know how to implement my exiting activities.
Since 3 days I'm looking for an solution...
So it would be great if someone can give me a solution or hint.
Thank you!
These are fragment files:
MainActivity
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class MainActivity extends SherlockFragmentActivity {
public static Context appContext;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//ActionBar gets initiated
ActionBar actionbar = getSupportActionBar();
//Tell the ActionBar we want to use Tabs.
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
//initiating both tabs and set text to it.
ActionBar.Tab PlayerTab = actionbar.newTab().setText("Fragment A");
ActionBar.Tab StationsTab = actionbar.newTab().setText("Fragment B");
//create the two fragments we want to use for display content
Fragment PlayerFragment = new AFragment();
Fragment StationsFragment = new BFragment();
//set the Tab listener. Now we can listen for clicks.
PlayerTab.setTabListener(new MyTabsListener(PlayerFragment));
StationsTab.setTabListener(new MyTabsListener(StationsFragment));
//add the two tabs to the actionbar
actionbar.addTab(PlayerTab);
actionbar.addTab(StationsTab);
}
class MyTabsListener implements ActionBar.TabListener {
public Fragment fragment;
public MyTabsListener(Fragment fragment) {
this.fragment = fragment;
}
#Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
//Toast.makeText(MainActivity.appContext, "Reselected!", Toast.LENGTH_LONG).show();
}
#Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
ft.replace(R.id.fragment_container, fragment);
}
#Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
ft.remove(fragment);
}
}
}
AFragment
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class AFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.afragment, container, false);
}
}
BFragment
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class BFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.bfragment, container, false);
}
}
And here is an exiting Activity
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Admin_Activity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.admin);
//Something else
//Database / Cursor actions
//...
//Listener Button
Button button_xy = (Button) this.findViewById(R.id.button_xy);
button_xy.setOnClickListener(this);
//...
public void onClick(View v) {
switch(v.getId()) {
case R.id.buttonxy:
//intent...
break;
}
}
}

Eclipse WebView

I would like to open url´s in webview instead of in a webbrowser. I´m no programmer and can´t find a solution. Help would be greatly apreciated. I would like the url to open in a new activity called: activity_webview. Thanks in advance
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import com.casovi.luxury_new.R;
public class MainCars extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cars);
}
public void GoKoenigsegg(View view) {
goToUrl("http://www.koenigsegg.com/");
}
public void GoMercedes(View view) {
goToUrl("http://www.mercedes-amg.com/#/home");
}
private void goToUrl(String url) {
Uri uriUrl = Uri.parse(url);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
}
}
Make your main activity like this:
first create a webview,
second enable webviewclients,
third enable contentview,
finally load your desired url.
All the best..
public class MainCars extends Activity {
WebView web;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = (WebView) findViewById(R.id.webView1);
web = new WebView(this);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://www.koenigsegg.com/");
web.setWebViewClient(new myWebClient());
web.setWebChromeClient(new WebChromeClient());
setContentView(web);
}

accessing array with object

hi i have two classes in android and in one class i have write an array and i want to access it in the main class but the error is give me that "force closed" here is my code
package com.semanticnotion.DAO;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class DAO extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WordsDAO DAO = new WordsDAO(new String[] "Arte","Arquitectura","Familia","Moda","Cotilleos","Cine","Libros","Historia","Pintura","Musica","Tendencies","Modernimso","Pop art","Masteialismo","realities","filosofia","moda","fotografia","religion"});
Button next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), WordsDAO.class);
startActivity(myIntent);
}
});
}
}
and the second class code is
package com.semanticnotion.DAO;
public class WordsDAO
{
String[] words = new String[] "Arte","Arquitectura","Familia","Moda","Cotilleos","Cine","Libros","Historia","Pintura","Musica","Tendencies","Modernimso","Pop art","Masteialismo","realities","filosofia","moda","fotografia","religion"};
public WordsDAO(String[] words )
{
this.words=words;
}
}
please any one tell what well be the error in this code thaks
First of all: the constructor in your second class would not be used. The way to pass parameters to another activity is to use Intent.putExtra in the code calling the other activity and in your other activity use
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
String value = extras.getString("keyName");
}
to get the data in onCreate.
That said, I guess the problem arises from your second class not providing an explicit parameterless constructor.