I want to know why it cannot open up new java class.
When I try to start new activity, it will be crash.
public class MainActivity extends ActionBarActivity {
EditText emailEt;
TextView registerET;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emailEt = (EditText) findViewById(R.id.email);
registerET = (TextView) findViewById(R.id.register);
registerET.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("clicks","You Clicked register page");
Intent myIntent = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(myIntent);
MainActivity.this.finish();
}
});
}
public void OnLogin(View view) {
String username = emailEt.getText().toString();
String type = "login";
BackgroundWorker backgroundWorker = new BackgroundWorker(this);
backgroundWorker.execute(type, username);
}
}
It's possible manifests problem? Am I put it wrong position for the activity?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a20_1discussboard">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>"
<application
android:allowBackup="true"
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>
<activity android:label="#string/app_name" android:name=".RegisterActivity"/>
</manifest>
It look like can be open up new java class, but it still display MainActivity.
Error Log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.a20_1discussboard, PID: 2194
java.lang.IllegalStateException: Could not find method onClick(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatTextView with id 'register'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:327)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Put proper Menifest format:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a20_1discussboard">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>"
<application
android:allowBackup="true"
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>
<activity android:label="#string/app_name"
android:name=".RegisterActivity"/> //<---here
</application>
</manifest>
Don't call finish(), this caused your crash:
registerET.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i("clicks","You Clicked register page");
Intent myIntent = new Intent(MainActivity.this, RegisterActivity.class);
startActivity(myIntent);
//remove finish();
}
});
Try declared activity in application in your AndroidManifest.xml like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a20_1discussboard">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>"
<application
android:allowBackup="true"
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>
<activity android:label="#string/app_name"
android:name=".RegisterActivity"/>
</application>
</manifest>
Be sure that you add RegisterActivity to your AndroidManifest.xml inside <application> tag:
<application ...>
...
<activity
android:label="#string/app_name"
android:name=".RegisterActivity"/>
</application>
Delete this line from onCreate method: MainActivity.this.finish();
If you want to stop or pause MainActivity, use:
#Override
public void onPause() { }
or
#Override
public void onStop() { }
in MainActivity class.
Thanks all.
Add RegisterActivity to AndroidManifest.xml inside <application> tag and remove MainActivity.this.finish()
It is working now.
Related
i'm a student and i'm working on a mobile app.
The probleme is that my app was working, but now when i click on the button to open another window it closes.
Here is my code:
`
public class MainActivity extends AppCompatActivity {
Button b_inscrire_etudiant;
Button b_inscrire_enseignant;
Button b_inscrire_admin;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b_inscrire_etudiant = findViewById(R.id.b_inscrire_etudiant);
b_inscrire_enseignant = findViewById(R.id.b_inscrire_enseignat);
b_inscrire_admin = findViewById(R.id.b_inscrire_admin);
b_inscrire_etudiant.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this , InscriptionEtudiant.class);
startActivity(i);
}
});
b_inscrire_enseignant.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this , InscriptionEnseignant.class);
startActivity(i);
}
});
b_inscrire_admin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this , InscriptionAdmin.class);
startActivity(i);
}
});
}
}
`
I worked as usual "using Intent" besides it worked well until now.
Here is my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.myusto">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MyUsto"
tools:targetApi="31">
<activity
android:name=".InscriptionEnseignant"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".InscriptionEtudiant"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".InscriptionAdmin"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".Connexion"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
ps: I solved the problem, by the way two were missing
Thank you for the answers.
It's true, it was missing a part of the code which was not written in the manifest file
So I am redoing my app so that there will be an animation on the start screen of the app. The only problem is it seems you cannot start an app with a view class. At least I'm not really sure if you can. Here is my code. With this code i get a launcher activity not found in the console?
public class SplashLaunch extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splashlaunch);
final Main d = new Main(this);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
setContentView(d);
}
}, 5000);
}
}
Here is the manifest file. I have a feeling that I'm going to need to change this.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Tripps.thesimplegame"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".SplashLaunch"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SPLASHLAUNCH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".YouFailed"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.YOUFAILED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Likely somewhere in your launcher activity you have an onCreate method:
public class YourActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.foobar);
}
}
Just change the setContentView to your custom view:
public class YourActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
MyCustomView view = new MyCustomView(this);
setContentView(view);
}
}
The Activity that you want to start when the app first starts MUST have the following Intent filter:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Okay so I've been messing around with the Twitter API, and all of a sudden I've started to get the ClassNotFoundException error code when I try and enter the Activity which has my login box to sign into Twitter.
Here's the error code.
2398-2398/josh.com.twitterapi E/dalvikvm﹕ Could not find class 'josh.com.twitterapi.LoginActivity', referenced from method josh.com.twitterapi.NavigationDrawerFragment.selectItem
07-05 02:19:30.138 2398-2398/josh.com.twitterapi E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: josh.com.twitterapi.LoginActivity
at josh.com.twitterapi.NavigationDrawerFragment.selectItem(NavigationDrawerFragment.java:204)
at josh.com.twitterapi.NavigationDrawerFragment.access$000(NavigationDrawerFragment.java:32)
at josh.com.twitterapi.NavigationDrawerFragment$1.onItemClick(NavigationDrawerFragment.java:99)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
at android.widget.AbsListView$1.run(AbsListView.java:3973)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
07-05 02:21:03.973 3223-3223/josh.com.twitterapi E/dalvikvm﹕ Could not find class 'josh.com.twitterapi.LoginActivity', referenced from method josh.com.twitterapi.NavigationDrawerFragment.selectItem
This is my LoginActivity.java.
package josh.com.socialme;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import com.codepath.oauth.OAuthLoginActivity;
public class LoginActivity extends OAuthLoginActivity<TwitterClient> {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
// Inflate the menu; this adds items to the action bar if it is present.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
// OAuth authenticated successfully, launch primary authenticated activity
// i.e Display application "homepage"
#Override
public void onLoginSuccess() {
// Intent i = new Intent(this, PhotosActivity.class);
// startActivity(i);
}
// OAuth authentication flow failed, handle the error
// i.e Display an error dialog or toast
#Override
public void onLoginFailure(Exception e) {
e.printStackTrace();
}
// Click handler method for the button used to start OAuth flow
// Uses the client to initiate OAuth authorization
// This should be tied to a button used to login
public void loginToRest(View view) {
getClient().connect();
}
}
This is my AndroidManifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.socialme" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<activity
android:name=".Hub"
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=".Feed"
android:label="#string/title_activity_feed" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
And this is my method I use to get to the activity.
private void selectItem(int position) {
// Handle Navigation Options
Intent intent;
switch (position) {
case 1:
intent = new Intent(getActivity(), Feed.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
break;
case 2:
intent = new Intent(getActivity(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
break;
}
}
I would greatly appreciate it if someone could point me towards the right direction.
Kind regards,
Josh
(AndroidManifest.xml as requested)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.socialme" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<activity
android:name=".Hub"
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=".Feed"
android:label="#string/title_activity_feed" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_login_activity" >
</activity>
</application>
</manifest>
I want to run an implicitly tried with the following code:
MenuActivity.java
public class MenuActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
Button btn = (Button) findViewById(R.id.btnVideo);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri intentUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.pp);
intent.setDataAndType(intentUri,"audio/mp3");
startActivity(intent);
}
});
}
}
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/iconopp14"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.powerpump.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MenuActivity" />
</application>
You need to specify more parameters in AndroidManifest.xml?
Thanks.
I guess you simply have to register your MenuActivity in you AndroidManifest.xml as demonstrated here.
Looking at your code, it looks like you created a MenuActivity class after creating an android project with default settings and MenuActivity is your main activity(Launcher) class.
Just replace the MainActivity with MenuActivity in your AndroidManifest.xml file and delete
<activity android:name=".MenuActivity" />
OR
Replace the class name to MainActivity from MenuActivity in your java code as follows
public class MainActivity extends Activity {
......
OR
use this as your android manifest.xml file
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/iconopp14"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name="com.powerpump.MenuActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I am a beginner of Android and i need a bit hints and help. I am using following code
public class WifiHotSpotActivity extends Activity {
private Button adnew = null;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
adnew = (Button) findViewById(R.id.addNewBtn);
adnew.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent(v.getContext(), addNew.class);
startActivityForResult(myIntent, 0);
}
});
}
The error i am receiving is
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.kahaf.wifiHotSpot/com.kahaf.wifiHotSpot.addNew}; have you declared this activity in your AndroidManifest.xml?
if anyone can tell me what is the problem.
You should define your activity in the manifest file. Here's an example how your manifest should look after the addition of that activity:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.foo.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:label="#string/app_name"
android:name=".FooActivity"
android:configChanges="keyboardHidden">"
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".YourActivityNameHere"
android:label="#string/app_name"
>
</activity>
<activity
android:name=".AnotherActivity"
android:label="#string/app_name"
>
</activity>
</application>
</manifest>
put this to AndroidManifest.xml
<activity android:name=".WifiHotSpotActivity"/>
It looks like you've not defined the Activity Element in the manifest xml for WifiHotSpotActivity. Without this you will be unable to launch this activity.
go to manifest the application tag.. add activity "addNew" which you are calling in button click..