In following code shown below
I am trying open a new activity(memo.class to view.class) when click view button.but showing an error "activity not found exception: unable to find explicit activity class".
what is wrong in my code??
please help me
my code:
memo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<TextView android:text="Titile" android:id="#+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:id="#+id/question" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
<TextView android:text="Text" android:id="#+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:minLines="6" android:maxLines="10" android:id="#+id/answer" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
<TableLayout android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button android:id="#+id/add" android:layout_width="wrap_content" android:text="ADD" android:layout_height="wrap_content"></Button>
<Button android:id="#+id/view" android:layout_width="wrap_content" android:text="VIEW" android:layout_height="wrap_content"></Button>
</TableRow>
</TableLayout>
</LinearLayout>
memo.java
package quesansw.the1;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class Memo extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Dialog d1 = new Dialog(this);
Window window = d1.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
d1.setTitle("Register Questions");
d1.setContentView(R.layout.memo);
d1.show();
Button view1 = (Button) d1.findViewById(R.id.view);
Button add = (Button) d1.findViewById(R.id.add);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
EditText add = (EditText) d1.findViewById(R.id.question);
EditText view = (EditText) d1.findViewById(R.id.answer);
System.out.println(add.getText());
System.out.println(view.getText());
}
});
view1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
Intent intent = new Intent(getBaseContext(), View.class);
startActivity(intent);
}
});
}
}
view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<EditText android:id="#+id/question" android:layout_width="match_parent" android:layout_height="wrap_content" android:text=""></EditText>
</LinearLayout>
view.java
package quesansw.the1;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class View extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Dialog d1 = new Dialog(this);
Window window = d1.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
d1.setTitle("Login");
d1.setContentView(R.layout.view);
d1.show();
}
}
You should declare the Activity in the manifest:
<activity
android:name="com.yourpackagename.View"/>
Basically, your AndroidManifest.xml file (found in the root package folder) acts as a "settings" or "main controller" for your entire application, and so the system needs to be aware of each activity (essentially a page) that you will transition to or use.
Here are other things that can go within the Activity tag in the Manifest file.
Side Note: as #Tyler M. says, you should use another name than "View" for your Activity.
Rename your Activity subclass to something other than View.
It is generally a bad idea to use names of existing classes - it is a reference disaster waiting to happen.
You most likely forgot to include it in the Manifest.xml
Related
I have created a new .xml file named "new_game.xml" and a class named "New_Game.java"
These are not Main activity
new_game.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:id="#+id/button"
android:layout_marginTop="27dp"
android:layout_alignRight="#+id/editText"/>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editText"
android:layout_marginTop="16dp"
android:layout_below="#+id/button"
android:layout_marginLeft="11dp"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:paddingTop="50dp"
android:paddingBottom="50dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:background="#drawable/ic_launcher"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/button"/>
</RelativeLayout>
New_Game.java:
package com.example.logosquiz;
import android.app.Activity;
import android.app.ListActivity;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class New_Game extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_game);
Button button1 = (Button)findViewById(R.id.button);
final EditText editText1 = (EditText)findViewById(R.id.editText);
ImageView imageView1 = (ImageView)findViewById(R.id.imageView);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
editText1.setText("Hello Android");
}
});
}
Please explain it very well
I put on AndroidManifest.xml this
<activity android:name=".New_Game"> /activity>
and this on the event onClick
Intent myIntent = new Intent(v.getContext(), New_Game.class);
startActivityForResult(myIntent, 0);
Your XML is wrong. Remove the last / from the first RelativeLayout in your XML.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
instead of
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Although Eclipse should have warned you about this.
your code is correct but
button android:layout_marginTop="27dp"
edittext android:layout_marginTop="16dp"
edit text is placed on the button so when you click you are clicking on edittext not button change edittext marginTop to 30dp and check
public class New_Game extends Activity {
EditText editText1;
#override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_game);
Button button1 = (Button)findViewById(R.id.button);
editText1 = (EditText)findViewById(R.id.editText);
ImageView imageView1 = (ImageView)findViewById(R.id.imageView);
button1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
editText1.setText("Hello Android");
}
});
}
package com.example.hello.word;
import android.R;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;
public class OptionsMenu extends Activity{
MediaPlayer ourSong;
Button btn1;
Intent openStartingPoint;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.menuoptions);
final ToggleButton onTog = (ToggleButton) findViewById(R.id.toggleButton1);
onTog.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (onTog.isChecked()){
ourSong.start();
}else{
ourSong.stop();
}
}
});
I have an error under all the Buttons and its shows me for example: "menuoptions cannot be resolved or is not field".. the same error on togglebutton1
my XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Volume"
android:textSize="40dp"
android:textStyle="bold"
android:layout_marginTop="40dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ToggleButton
android:id="#+id/toggleButton1"
android:layout_width="121dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="ToggleButton" />
<Button
android:id="#+id/button1"
android:layout_width="178dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="150dp"
android:text="Back" />
</LinearLayout>
I tried to clean the project.. delete the R class and everything! what I can do to fix that Error?
Thanx for helpers..
You are getting that error because your are importing android.R you have to remove this import.
Try removing the line import android.R; from your code, this should fix your problem
When you press control + shift + O to organise your imports in eclipse, it sometimes adds the import for android.R
Here is a similar question
R cannot be resolved - Android error
I'm very new with android development. I'm trying to develop an application, I decided to try out the code below but I keep getting errors when I try to open it on the emulator. please can anyone tell me what I'm doing wrong?
package hajara.android.MyRecipes;
import android.app.Activity;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MyRecipesActivity extends Activity {
Button btn;
TextView t1, t2;
EditText e;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
t1 = (TextView)findViewById(R.id.text1);
t2 = (TextView)findViewById(R.id.text2);
e = (EditText)findViewById(R.id.edit1);
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener((OnClickListener) this);
}
}
My main.xml file is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter a string:"
/>
<EditText android:id="#+id/edit1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="true"
android:editable="true"
android:singleLine="true"
/>
<Button android:id="#+id/button1"
android:text="OK"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
</LinearLayout>
Your onClick listener is done incorrectly. I find it easier to simply create a method such as:
public void buttonOnClick(View v) {
// Do something
}
and within your XML layout file (ie. main.xml) invoke the onClick attribute:
<Button
...
android:onClick="buttonOnClick"
...
/>
I think you haven't Declared button Properly.
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Your Code Goes here
}
});
And Hope you have Declared your Activity in Manifest File.
i want to have a set of buttons and the focus on buttons should change periodically first i want to try it with 2 buttons.this is my main.xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/number_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.72"
android:focusable="true"
android:gravity="center"
android:text="#string/number"
android:textSize="10pt" android:clickable="true"
android:focusableInTouchMode="true"/>
<Button
android:text="#string/contact"
android:textSize="10pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/contact_button"
android:layout_weight="1" android:layout_gravity="center"
android:focusable="true" android:gravity="center"
android:focusableInTouchMode="true"/>
</LinearLayout>
in the source code i have used FOCUS_LEFT,RIGHT and all other options ,but i am getting a run time exception. the orientation is set as vertical in linear layout.Please help me to sort out this problem, if anybody know how to set the timer option as well post it here
here is the code
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class HelloandroidActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Object o=null;
// o.toString();
// TextView tv = new TextView(this);
// tv.setText("Hello Andriod");
setContentView(R.layout.main);
Button mybtn= (Button)findViewById(R.id.number_button);
mybtn.requestFocus();
try
{
Button mybtn2= (Button)mybtn.focusSearch(View.FOCUS_DOWN);
mybtn2.requestFocus();
}
catch(Exception e)
{
Log.e("focus change","focus failed",e);
}
}
}
The problem is that you is finding a control in mybtn. Inside your activity you should call focusSearch in Activity context. Try this:
Button mybtn2 = (Button) focusSearch(View.FOCUS_DOWN);
if (mybtn2 != null)
mybtn2.requestFocus();
I am trying to create 5 buttons in my main activity and am trying to put new activities in them.
In the fifth button, I am having a problem with listView.
In the below code, am I missing anything required for the listView(View v) method to work properly?
Here is my code:
listActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="newActivity"
android:text="Yeni Aktivite" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="toast"
android:text="Toast" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="web"
android:text="Web" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="preferences"
android:text="Preferences" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="listVieww"
android:text="ListView" />
</LinearLayout>
Main activity
package com.uygulamalar.odev;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class OdevKarmaActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void newActivity(View v) {
Intent intent = new Intent(getApplicationContext(), NewActivity.class);
startActivity(intent);
}
public void toast(View v) {
Toast toast=Toast.makeText(getApplicationContext(), "vazzupp", 9999);
toast.show();
}
public void listVieww(View v) {
ListView listView1;
String jedigiller[] = {"pelin","figen","aylin","gizem"};
listView1=(ListView) findViewById(R.id.listView1);
listView1.setAdapter(new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , jedigiller));
}
}
When run, the code forces the Android emulator to close.
I am suspecting that the issue is related to the listView(View v) method, did I miss anything when using it?
You are attempting to reference a ListView found in listActivity.xml, while you have set your content view to main.xml.
Either copy the ListView over to main.xml, or start a new Activity in listVieww() that displays the list, and uses setContentView(R.layout.listActivity);