is not assignable to android.app.activity - android

My project has showing red highlighted text I need my project fixed
am not sure what has caused this to happen any suggestions.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="scrape2.myapplication" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="scrape2.myapplication.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=".MainActivity2Activity"
android:label="#string/title_activity_main_activity2" >
</activity>
</application>
</manifest>
<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"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/parse_html"
android:id="#+id/html_content"
android:textSize="16sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="119dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:text="html"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_x="186dp"
android:layout_y="1dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/parse_html"
android:id="#+id/textView1"
android:textSize="16sp"
android:singleLine="false"
android:layout_marginTop="107dp"
android:layout_below="#+id/html_content" />
<ListView
android:id="#+id/listView2"
android:layout_width="355dp"
android:layout_height="421dp"
android:layout_x="20dp"
android:layout_y="118dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/button"
android:layout_toStartOf="#+id/button"
android:layout_x="264dp"
android:layout_y="-1dp" />
</RelativeLayout>
I am not sure why its doing that please share me some tip thanks.
I tried to clean the project , also clicked the rebuild still no luck
activity class
package scrape2.myapplication;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import static scrape2.myapplication.Constants.FIFTH_COLUMN;
import static scrape2.myapplication.Constants.FIRST_COLUMN;
import static scrape2.myapplication.Constants.FOURTH_COLUMN;
import static scrape2.myapplication.Constants.SECOND_COLUMN;
import static scrape2.myapplication.Constants.THIRD_COLUMN;
public class MainActivity extends ActionBarActivity {
private ArrayList<HashMap<String, String>> list;
public int count = 0;
public String temp;
private Document htmlDocument;
private String htmlPageUrl = "http://en.masjidway.com/masjid/2804/prayer";
private TextView parsedHtmlNode;
private TextView textViewwww;
private String htmlContentInStringFormat;
private String dayys;
private String amarrdatta;
private String duhr_val1;
private String asr_val1;
private String maghreb_val1;
private String isha_val1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
parsedHtmlNode = (TextView)findViewById(R.id.html_content);
textViewwww = (TextView)findViewById(R.id.textView1);
Button button2 = (Button)findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(MainActivity.this, MainActivity2Activity.class);
MainActivity.this.startActivity(myIntent);
}
});
Button htmlTitleButton = (Button)findViewById(R.id.button);
htmlTitleButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
JsoupAsyncTask jsoupAsyncTask = new JsoupAsyncTask();
jsoupAsyncTask.execute();
}
});
w(ListView)findViewById(R.id.listView2);
String zuhrr =duhr_val1;//2
w

Your RelativeLayout doesn't belong in AndroidManifest.xml. You should create a new xml file for every layout.

I think i have found a solution i have done many checks and for some reason the project plays up not sure why this is the test i have done at first
from relatetive layout changed only this name to linerlayout
then pressed
clean project
rebuild
run project then once it compiles the file opens the emulator or phone press cancle.
then close the project and open it , it fixes it.
also you can just leave it as reletive layout and do the remaining steps it will fix it.
am not sure why it does that.

Related

Android Firebase create user task not show error but not working

I'm learning from youtube how to create user from firebase using android studio. I've follow the istruction correctly but I've got problem. The problem is, the .createUserWithEmailAndPassword syntax. It seems that the task for creating the user is not working but not show any error on log. I've did what suggestion provided on stackoverflow.com, but the problem still occur. Please help me to solve this problem. Thank you
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ahmadfaza.newfoodorderclient">
<uses-permission android:name="android.permission.INTERNET"/>
<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"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.ahmadfaza.newfoodorderclient.MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Up"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter email"
android:id="#+id/editEmail"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter password"
android:id="#+id/editPass"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Up"
android:onClick="signupButtonClicked"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Already have an account ?"
android:layout_marginTop="250dp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign In"
android:onClick="signinButtonClicked"
/>
</LinearLayout>
MainActivity.java
package com.example.ahmadfaza.newfoodorderclient;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends AppCompatActivity {
private EditText email,pass;
private DatabaseReference mDatabase;
private FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
email = (EditText) findViewById(R.id.editEmail);
pass = (EditText) findViewById(R.id.editPass);
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference().child("users");
}
public void signupButtonClicked(View view)
{
final String email_text = email.getText().toString().trim();
final String pass_text = pass.getText().toString().trim();
if(!TextUtils.isEmpty(email_text) && !TextUtils.isEmpty(pass_text))
{
mAuth.createUserWithEmailAndPassword(email_text,pass_text).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful())
{
String user_id = mAuth.getCurrentUser().getUid();
DatabaseReference current_user = mDatabase.child(user_id);
current_user.child("Name").setValue(email_text);
}
}
});
}
}
}

Application run on emulator but stopped on mobile

I am trying to read my GPS position. It works on emulator Nexus S API 23
But when install it on Deices with 4.1.1 or 5.0.1 versions it stopped before working. i need to know that if the problem because of the code or because of the different versions between devices:
this is my code:
Main Activity.java
package com.example.user.getgps1;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
static final long meter=1;
static final long mill=1000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocationManager manager=(LocationManager) this.getSystemService(context.LOCATION_SERVICE);
if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED||checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, meter, mill, new locationlist(this));
}
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER,meter,mill,new locationlist(this));
}
ProgressDialog dialog;
Context context;
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void bulocation(View view) {
context = this;
dialog = new ProgressDialog(MainActivity.this);
dialog.show();
dialog.setMessage("Getting Last Location");
LocationManager locationmanager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED||checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, meter, mill, new locationlist(this));
}
Location lastknown = locationmanager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(lastknown==null)
lastknown=locationmanager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
TextView t1=(TextView) findViewById(R.id.textView1);
TextView t2=(TextView) findViewById(R.id.textView2);
t2.setText(Double.toString(lastknown.getLatitude()));
t1.setText(Double.toString(lastknown.getLongitude()));
dialog.dismiss();
}
}
activity_main
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="#string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView1"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView2"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:onClick="bulocation"/>
</RelativeLayout>
Android_manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.user.getgps1" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
</application>
</manifest>
locationlist.java
package com.example.user.getgps1;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.widget.Toast;
public class locationlist implements LocationListener {
Context context;
public locationlist(Context context)
{
this.context=context;
}
#Override
public void onLocationChanged(Location location) {
Toast.makeText(context,"log:"+Double.toString(location.getLongitude())+", lat: "+Double.toString(location.getLatitude()),Toast.LENGTH_LONG).show();
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Toast.makeText(context,"GPS is Changed",Toast.LENGTH_LONG).show();
}
#Override
public void onProviderEnabled(String provider) {
Toast.makeText(context,"GPS is on",Toast.LENGTH_LONG).show();
}
#Override
public void onProviderDisabled(String provider) {
Toast.makeText(context,"GPS is OFF",Toast.LENGTH_LONG).show();
}
}
what is the problem
Looking at the logcat you posted as answer.
Your call to getLastKnownLocation() is returning null.
On a real device you cant assume to always get a location,
Hope this helps.

Why placing a call programatically gives error message "Internet Calling not Supported"?

This is my code:
public String a_number;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_make_the_call);
//
callButton = (ImageButton)findViewById(R.id.call_button);
aCall = (TextView)findViewById(R.id.number_a);
a_number = aCall.getText().toString();
}
public void makeCallFunction(View view) {
String temp = "";
temp = "tel:"+a_number;
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(temp));
startActivity(callIntent);
}
My XML file contains:
<ImageButton
android:id="#+id/call_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:src="#drawable/dial"
android:onClick="makeCallFunction"/>
I have added the following in my manifest file:
<uses-permission android:name="android.permission.CALL_PHONE"/>
I searched my best for answers but found nothing helpful..
EDIT:
When I give a value directly, the call gets placed now.
Eg:
callIntent.setData(Uri.parse("tel:9876543210"));
But the problem remains when I read the number from my text view and try to place call with that number.
Can someone help me out?
Thanks in advance
If there's some alternate way to implement call, that'd help too.
Disable SIP Internet Calling and VoIP on your emulator or debugging device. This is the steps for Samsung Galaxy S4 :
go to settings > call > disable internet calling(in bottom)
I don't know what you are doing wrong, but see for yourself a working example :
MakeTheCallActivity.java
package com.example.makethecall;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MakeTheCallActivity extends ActionBarActivity {
private EditText mEditText;
private Button mButton;
private final String TAG = "MakeTheCallActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_make_the_call);
mButton = (Button)findViewById(R.id.call_button);
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mEditText = (EditText)findViewById(R.id.phone_number);
String phoneNumber = mEditText.getText().toString();
Log.d(TAG, phoneNumber);
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
startActivity(intent);
}
});
}
}
activity_make_the_call.xml
<LinearLayout 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" tools:context=".MakeTheCallActivity"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/phone_number" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="call"
android:id="#+id/call_button" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sauravsamamt.makethecall" >
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MakeTheCallActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You can see I'm not using a hardcoded number. Make sure you enter a valid number. That's it.

Numeric login app does not switch activities?

Hi I have a basic app for logging in with hardcoded credentials, and I want it to take you to another activity called Welcome. Here is my main activity:
package com.example.numericlogin;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.os.Build;
public class MainActivity extends Activity{
private EditText login_key=null;
private Button login=null;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login_key = (EditText)findViewById(R.id.editText1);
login = (Button)findViewById(R.id.login);
}
public void login(View view){
if(login_key.getText().toString().equals("123456")){
Toast.makeText(getApplicationContext(), "Login Successful!",
Toast.LENGTH_LONG).show();
startActivity(new Intent(MainActivity.this,Welcome.class));
}
else{
Toast.makeText(getApplicationContext(), "Wrong Credentials",
Toast.LENGTH_SHORT).show();
{
login.setEnabled(false);
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Here is the main activity's 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.numericlogin.MainActivity$PlaceholderFragment" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_key" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView1"
android:ems="10"
android:digits="0123456789"
android:inputType="number|textPassword"
android:maxLength="6"
android:password="true"
/>
<Button
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:text="#string/login" />
</RelativeLayout>
Here is the second activity I want it to switch to when logged in correctly:
package com.example.numericlogin;
import android.view.View;
import android.widget.ImageView;
public class Welcome {
public void welcome(View v){
ImageView picture = (ImageView)
setContenView(R.layout.fragment_main);
}
private ImageView setContenView(int fragmentMain) {
// TODO Auto-generated method stub
return null;
}
}
Here is the xml for the above activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="74dp"
android:src="#drawable/welcome" />
</RelativeLayout>
And here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.numericlogin"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.numericlogin.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=".Welcome"/>
</application>
</manifest>
At the moment when I launch it it brings up the first activity and allows you to enter input in the login area, but when you click the login button nothing happens. There are no errors in the code and here is the logcat output:
07-01 14:11:15.313: W/IInputConnectionWrapper(23128): showStatusIcon on inactive InputConnection
This is how you switch between activities:
In MainActivity.java:
Intent go = new Intent(this, Welcome.class);
startActivity(go);
Your second activity class must extend Activity
public class Welcome extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.childact);
}
}
And you must register all activities in manifest file.
You are missing this:
<activity
android:name="com.example.testingproj.Welcome"
android:label="#string/app_name">
</activity>
I think you forgot set onClickListener for the login button or set attribute onClick with value 'login' in the properties panel in graphical layout preview.
final Button login= (Button) findViewById(R.id.login);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform code validation
}
});

How can i fix android app notepad issue? (listactivity)

I am trying to create an android app notepad, but for some reason the app crashes when it goes to the page with ListView. I believe that the problem is that the class extends in ListActivity. Can someone plz help me?
The NotesList class code:
package com.tim.csproject2;
import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;
public class NotesList extends ListActivity implements OnClickListener{
private static final int ACTIVITY_CREATE = 0;
private static final int ACTIVITY_EDIT = 1;
private static final int INSERT_ID = Menu.FIRST;
private static final int DELETE_ID = Menu.FIRST+1;
private static final int EDIT_ID = Menu.FIRST+2;
private Button add, back, advanced;
private ListView listV;
private NotesDbAdapter myHelper;
private Cursor myCursor;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.notes_menu);
add = (Button) findViewById(R.id.add1);
back = (Button) findViewById(R.id.back1);
advanced = (Button) findViewById(R.id.advanced1);
listV = (ListView) findViewById(R.id.listsList);
add.setOnClickListener(this);
back.setOnClickListener(this);
advanced.setOnClickListener(this);
listV.getAdapter();
myHelper = new NotesDbAdapter(this);
myHelper.open();
fillData();
registerForContextMenu(getListView());
}
private void fillData() {
// Get all of the rows from the database and create the item list
myCursor = myHelper.fetchAllNotes();
startManagingCursor(myCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{NotesDbAdapter.KEY_TITLE};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.notes_row, myCursor, from, to);
setListAdapter(notes);
}
private void createNote() {
Intent i = new Intent(this, NoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
the note_menu xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<Button
android:id="#+id/advanced1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:text="Advanced Menu"
android:textSize="20dp"
/>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/no_notes"
/>
<Button
android:id="#+id/add1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Add Note"
android:textSize="20dp"
/>
<Button
android:id="#+id/back1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Back"
android:textSize="20dp"
/>
</LinearLayout>
the nores_row xml file:
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id= "#+id/text1" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
the android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tim.csproject2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.tim.csproject2.IntroClass"
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=".MainMenu"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.tim.csproject2.MAINMENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".NotesList"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.tim.csproject2.NOTELIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ListsList"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.tim.csproject2.LISTSLIST" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".NoteEdit" />
</application>
</manifest>
One problem I can see is that
listV = (ListView) findViewById(R.id.listsList);
should be
listV = getListView();
Since your layout xml has the ListView with android:id="#android:id/list", you can also do:
listV = (ListView) findViewById(android.R.id.list);
minSdkVersion could be problem for SimpleCursorAdapter. instead of
import android.widget.SimpleCursorAdapter;
try
import android.support.v4.widget.SimpleCursorAdapter;

Categories

Resources