I just want to switch activity with a simple button
Button test = findViewById(R.id.please);
test.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("MainActivity","I pass there ");
Intent intent = new Intent(MainActivity.this, TestActivity.class);
startActivity(intent);
Log.d("MainActivity","I pass there too");
}
});
I don't have an error, I just arrive on a white screen and not on my new activity. Logs appear in my console. I also have a log when I create my second activity but this one doesn't appear.
for more code,
This is my manifest :
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HomeActivity">
</activity>
<activity android:name=".ScheduleActivity"></activity>
<activity android:name=".MapActivity"></activity>
<activity android:name=".TestActivity"
android:theme="#style/YourTheme">
</activity>
</application>
TestActivity :
public class TestActivity extends AppCompatActivity {
#Override
public void onCreate(#Nullable Bundle savedInstanceState, #Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_test);
Log.d("TestActivity","I arrived in Test Activity !!");
}
}
the button in activity_main :
</android.support.design.widget.AppBarLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="wtf"
android:background="#color/colorAccent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:id="#+id/please"
/>
Activity_test :
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_map_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello there! :D"/>
You are Overriding wrong onCreate method in TestActivity. You have to override this method:
protected void onCreate(#Nullable Bundle savedInstanceState) {}
I recently was studying making an AlarmReminder on youtube by this man's tutorial videos: DelaroyStudios.
Anyway... I followed his tutorial and made it work on a separate app. So next I modified it to the way I want my alarmreminder to be and tried to add it to my activity, however when I click the button routing to its activity launcher, it won't go off. By the way here's the repo: https://github.com/delaroy/AlarmReminder
I tried debugging but I can't see errors, so I really don't know where to start in fixing this part. But I suspect its on the dependencies on the gradle perhaps? or some other factor? Anyway please take a look at my code where I suspect the problem might be coming from.
Here's the manifests:
My Manifest
<application
android:name=".FireApp"
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="com.loginpack.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.loginpack.LoginActivity" />
<activity android:name=".MainActivity" />
<activity android:name="com.Welcome.Welcome" />
<activity android:name="com.Welcome.CalendarActivity" />
<activity android:name="com.Welcome.Video" />
<activity android:name=".Profile" />
<activity android:name="com.Welcome.Image">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity android:name="com.alarmreminder.MainReminder">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.alarmreminder.AddReminderActivity"
android:label="#string/title_activity_add_reminder"
android:parentActivityName="com.alarmreminder.MainReminder"
android:theme="#style/AppTheme">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.alarmreminder.MainReminder"
/>
</activity>
<activity android:name="com.Welcome.Info" />
<activity android:name=".Profile2" />
<activity android:name=".Profile3"/>
I checked the code and I suspect nothing except for some deprecated codes that were usually couldn't have affected the overall performance of the activity to the point that it can't even be opened and debugged. Please help me find a way to make this work. or perhaps if you know any method for me to debug activities without any errors showing. Oh and by the way this is what shows in the Verbose when I click on the activity.
Here's the code of the Activity mentioned:
public class MainReminder extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
private FloatingActionButton mAddReminderButton;
private Toolbar mToolbar;
AlarmCursorAdapter mCursorAdapter;
AlarmReminderDbHelper alarmReminderDbHelper = new AlarmReminderDbHelper(this);
ListView reminderListView;
private static final int VEHICLE_LOADER = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mainalarm);
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mToolbar.setTitle(R.string.app_name);
reminderListView = findViewById(R.id.list);
View emptyView = findViewById(R.id.empty_view);
reminderListView.setEmptyView(emptyView);
mCursorAdapter = new AlarmCursorAdapter(this, null);
reminderListView.setAdapter(mCursorAdapter);
reminderListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent intent = new Intent(MainReminder.this, AddReminderActivity.class);
Uri currentVehicleUri = ContentUris.withAppendedId(AlarmReminderContract.AlarmReminderEntry.CONTENT_URI, id);
// Set the URI on the data field of the intent
intent.setData(currentVehicleUri);
startActivity(intent);
}
});
mAddReminderButton = findViewById(R.id.fab);
mAddReminderButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), AddReminderActivity.class);
startActivity(intent);
}
});
getLoaderManager().initLoader(VEHICLE_LOADER, null, this);
}
#Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
String[] projection = {
AlarmReminderContract.AlarmReminderEntry._ID,
AlarmReminderContract.AlarmReminderEntry.KEY_TITLE,
AlarmReminderContract.AlarmReminderEntry.KEY_DATE,
AlarmReminderContract.AlarmReminderEntry.KEY_TIME,
AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT,
AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT_NO,
AlarmReminderContract.AlarmReminderEntry.KEY_REPEAT_TYPE,
AlarmReminderContract.AlarmReminderEntry.KEY_ACTIVE
};
return new CursorLoader(this, // Parent activity context
AlarmReminderContract.AlarmReminderEntry.CONTENT_URI, // Provider content URI to query
projection, // Columns to include in the resulting Cursor
null, // No selection clause
null, // No selection arguments
null); // Default sort order
}
#Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
mCursorAdapter.swapCursor(cursor);
}
#Override
public void onLoaderReset(Loader<Cursor> loader) {
mCursorAdapter.swapCursor(null);
}
}
PS: In the my manifest I didn't make it as the main launcher, since its only an activity after all.
it's my first time posting a question and i already tried more than 5 solutions being told in this site, but none of them works for me, the problem is the buttons are clickable, but not going anywhere i wanted them to, but the main page login button that leads to this page works with the same exact code, below is the menu code
public class AdminMenu extends Activity{
Button b1, b2, b3, b4, b5;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.admin_menu);
b1 = (Button)findViewById(R.id.staff);
b2 = (Button)findViewById(R.id.stock);
b3 = (Button)findViewById(R.id.incoming);
b4 = (Button)findViewById(R.id.outgoing);
b5 = (Button)findViewById(R.id.logout1);
b1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, StaffSelection.class);
startActivity(intent);
finish();
}
});
b2.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, StockSelection.class);
startActivity(intent);
finish();
}
});
b3.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, IncomingSelection.class);
startActivity(intent);
finish();
}
});
b4.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Redirecting...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, OutgoingSelection.class);
startActivity(intent);
finish();
}
});
b5.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
Toast.makeText(getApplicationContext(), "Logging Out...",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, Login.class);
startActivity(intent);
finish();
}
});
}
}
then here is the xml for the app interface
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#drawable/background">
<Button
android:layout_width="330dp"
android:layout_height="70dp"
android:text="STAFF"
android:id="#+id/staff"
android:layout_marginTop="23dp"
android:layout_marginLeft="23dp"
android:layout_marginStart="23dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="25dp"
android:background="#52cc85"
android:clickable="true"
android:contextClickable="true" />
<Button
android:layout_width="330dp"
android:layout_height="70dp"
android:text="STOCK"
android:id="#+id/stock"
android:layout_below="#+id/staff"
android:layout_alignLeft="#+id/staff"
android:layout_alignStart="#+id/staff"
android:layout_marginTop="20dp"
android:layout_alignRight="#+id/staff"
android:layout_alignEnd="#+id/staff"
android:textSize="25dp"
android:background="#52cccc"/>
<Button
android:layout_width="330dp"
android:layout_height="70dp"
android:text="INCOMING SHIPMENT"
android:id="#+id/incoming"
android:layout_below="#+id/stock"
android:layout_alignLeft="#+id/stock"
android:layout_alignStart="#+id/stock"
android:layout_marginTop="20dp"
android:layout_alignRight="#+id/stock"
android:layout_alignEnd="#+id/stock"
android:textSize="25dp"
android:background="#52cc85"/>
<Button
android:layout_width="330dp"
android:layout_height="70dp"
android:text="OUTGOING SHIPMENT"
android:id="#+id/outgoing"
android:layout_below="#+id/incoming"
android:layout_alignLeft="#+id/incoming"
android:layout_alignStart="#+id/incoming"
android:layout_marginTop="20dp"
android:layout_alignRight="#+id/incoming"
android:layout_alignEnd="#+id/incoming"
android:textSize="25dp"
android:background="#52cccc"/>
<Button
android:layout_width="150dp"
android:layout_height="70dp"
android:text="LOGOUT"
android:id="#+id/logout1"
android:layout_marginTop="20dp"
android:layout_below="#+id/outgoing"
android:layout_alignRight="#+id/outgoing"
android:layout_alignEnd="#+id/outgoing" />
</RelativeLayout>
and here is the manifest file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.reversesky.mwms">
<application android:allowBackup="true"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".User.Login">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".User.AdminMenu">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".User.StaffMenu">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".User.StaffSelection">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".IS.IncomingSelection">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".OS.OutgoingSelection">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".Stock.StockSelection">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".User.CreateStaff">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".IS.CreateIncoming">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".Stock.CreateStock">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".OS.CreateOutgoing">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
here is the UI1
Here are some Alternative solutions ,
ViewAnimator : This is useful for showing a quick animation, if you want to change the view multiple times in quick succession.
Fragments : Instead of re-drawing the entire view, you can switch out fragments. Each fragment is a kind of mini activity, and overall this will contain the code much better.
Start New Activity : Pass information to an activity to help it set up. The first activity passes information to a common second activity, which knows how to set itself up based off of the information it receives from the first activity.
I tried with your code, it works fine for me
Replace your code like this,
AdminMenu.class
public class AdminMenu extends Activity {
Button b1, b2, b3, b4, b5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.admin_menu);
b1 = (Button) findViewById(R.id.staff);
b2 = (Button) findViewById(R.id.stock);
b3 = (Button) findViewById(R.id.incoming);
b4 = (Button) findViewById(R.id.outgoing);
b5 = (Button) findViewById(R.id.logout1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AdminMenu.this, StaffSelection.class);
startActivity(intent);
}
});
}
}
StaffSelection.class
public class StaffSelection extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".AdminMenu">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StaffSelection"
android:label="#string/app_name"
/>
</application>
According to you add your class and other details.I have done only for Staff button click.
I've cleaned up Your solution a little bit.
Entire AndroidManifest.xml:
<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=".AdminMenuActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".CreateIncomingActivity"/>
<activity android:name=".CreateOutgoingActivity"/>
<activity android:name=".CreateStaffActivity"/>
<activity android:name=".CreateStockActivity"/>
<activity android:name=".IncomingSelectionActivity"/>
<activity android:name=".LoginActivity"/>
<activity android:name=".OutgoingSelectionActivity"/>
<activity android:name=".StaffMenuActivity"/>
<activity android:name=".StaffSelectionActivity"/>
<activity android:name=".StockSelectionActivity"/>
</application>
Please keep in mind You should align activities names as you wish.
In my recreation, every single activity (except AdminMenuActivity to demonstrate usage) is as silly as:
package com.stackoverflow.tommus.buttonsnotworking;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class CreateIncomingActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_incoming);
}
}
Please keep in mind you should use proper layout id in all activities.
Again, in my recreation every single layout (except activity_admin_menu to demonstrate usage) is as silly as:
Now is the important part.
My activity_menu_admin is the same as yours:
<Button
android:id="#+id/staff"
android:layout_width="330dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginStart="23dp"
android:layout_marginTop="23dp"
android:background="#52cc85"
android:clickable="true"
android:text="STAFF"
android:textSize="25dp"
/>
<Button
android:id="#+id/stock"
android:layout_width="330dp"
android:layout_height="70dp"
android:layout_alignEnd="#+id/staff"
android:layout_alignLeft="#+id/staff"
android:layout_alignRight="#+id/staff"
android:layout_alignStart="#+id/staff"
android:layout_below="#+id/staff"
android:layout_marginTop="20dp"
android:background="#52cccc"
android:text="STOCK"
android:textSize="25dp"
/>
<Button
android:id="#+id/incoming"
android:layout_width="330dp"
android:layout_height="70dp"
android:layout_alignEnd="#+id/stock"
android:layout_alignLeft="#+id/stock"
android:layout_alignRight="#+id/stock"
android:layout_alignStart="#+id/stock"
android:layout_below="#+id/stock"
android:layout_marginTop="20dp"
android:background="#52cc85"
android:text="INCOMING SHIPMENT"
android:textSize="25dp"
/>
<Button
android:id="#+id/outgoing"
android:layout_width="330dp"
android:layout_height="70dp"
android:layout_alignEnd="#+id/incoming"
android:layout_alignLeft="#+id/incoming"
android:layout_alignRight="#+id/incoming"
android:layout_alignStart="#+id/incoming"
android:layout_below="#+id/incoming"
android:layout_marginTop="20dp"
android:background="#52cccc"
android:text="OUTGOING SHIPMENT"
android:textSize="25dp"
/>
<Button
android:id="#+id/logout1"
android:layout_width="150dp"
android:layout_height="70dp"
android:layout_alignEnd="#+id/outgoing"
android:layout_alignRight="#+id/outgoing"
android:layout_below="#+id/outgoing"
android:layout_marginTop="20dp"
android:text="LOGOUT"
/>
AdminMenuActivity has some changes:
package com.stackoverflow.tommus.buttonsnotworking;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class AdminMenuActivity extends AppCompatActivity {
Button b1, b2, b3, b4, b5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_menu);
b1 = (Button) findViewById(R.id.staff);
b2 = (Button) findViewById(R.id.stock);
b3 = (Button) findViewById(R.id.incoming);
b4 = (Button) findViewById(R.id.outgoing);
b5 = (Button) findViewById(R.id.logout1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
navigateToActivity(CreateStaffActivity.class);
}
});
b2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
navigateToActivity(CreateStockActivity.class);
}
});
b3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
navigateToActivity(CreateIncomingActivity.class);
}
});
b4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Redirecting...", Toast.LENGTH_SHORT).show();
navigateToActivity(CreateOutgoingActivity.class);
}
});
b5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Logging Out...", Toast.LENGTH_SHORT).show();
navigateToActivity(LoginActivity.class);
}
});
}
private void navigateToActivity(Class<?> activityClass) {
final Intent intent = new Intent(this, activityClass);
startActivity(intent);
}
}
I am opening new activities with a use of Intents. This way I am sure when creating a new activity I have an activity with proper layout and not messed up ids.
Can you please remove line "android:contextClickable="true" from your b1 button in your xml file and then try again.
I created a register link but it doesn't work . I want the "Register Here" link to send me from the login page to the register page . It worked before when I got an answer to my previous question on here but now it's not working for me . Can someone help me ?
Login.java :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
etUsername = (EditText) findViewById(R.id.etUsername);
etPassword = (EditText) findViewById(R.id.etPassword);
tvRegisterLink = (TextView) findViewById(R.id.tvRegisterLink);
bLogin = (Button) findViewById(R.id.bLogin);
bLogin.setOnClickListener(this);
tvRegisterLink.setOnClickListener(this);
userLocalStore = new UserLocalStore(this);
}
AndroidManifest.xml :
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity"
android:label="Login register"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login"
android:label="Login" >
</activity>
<activity
android:name=".Register"
android:label="Register" >
</activity>
</application>
activity_login.xml :
<TextView
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register Here"
android:id="#+id/tvRegisterLink"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="onClick" />
You need to remove android:onClick="onClick" from your button and access the onClick from your OnClickListener. You need to choose one of the two methods. You can see them listed well in this answer Button on click listener
i'm still new at learning java and this is my first android app and it used to work but now it just shows me an error whenever i try to run this page :
package com.ds.rssreader;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
public class StartingPoint extends ListActivity {
Button Add;
Button Delete;
public static String Menu[];
public static int Menu_counter = 0;
ListView Sites;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.starting);
Add = (Button) findViewById(R.id.Add);
Delete = (Button) findViewById(R.id.Delete);
Sites = (ListView) findViewById(R.id.list);
Add.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenAddPage = new Intent("com.ds.rssreader.AddPage");
startActivity(OpenAddPage);
}
});
Delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent OpenDeletePage = new Intent(
"com.ds.rssreader.DeletePage");
startActivity(OpenDeletePage);
}
});
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
and here it's Layout:
<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"
android:padding="25dp"
tools:context="com.ds.rssreader.StartingPoint" >
<Button
android:id="#+id/Add"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Add"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/Delete"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Delete"
tools:ignore="HardcodedText" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/Add"
android:clickable="true"
tools:ignore="HardcodedText" >
</ListView>
</RelativeLayout>
and here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ds.rssreader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:name="android.permission.INTERNET"
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.ds.rssreader.Splash"
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.ds.rssreader.StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.StartingPoint" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.AddPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.AddPage" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.DeletePage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.DeletePage" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSFeed"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSFeed" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSHandler"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSHandler" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.ds.rssreader.RSSItem"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.ds.rssreader.RSSItem" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
the error causes the program to crash whenever i try to open this page and it says :
E/AndroidRuntime(1085): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ds.rssreader/com.ds.rssreader.StartingPoint}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
and when i try to debug it, it tells me that there is something's source not found
and for the record when i make any other page opens instead of this page it opens without any problems.
REMEMBER GUYS : I'm new in java so don't say big words try to simplify as much as you can
Thanks
In your layout, change:
android:id="#+id/list"
to
android:id="#id/android:list"
and, in your class change:
Sites = (ListView) findViewById(R.id.list);
to
Sites = (ListView) findViewById(android.R.id.list);