开始新活动

时间:2016-05-30 19:52:40

标签: javascript android android-studio

您好我正在尝试创建一个可以登录主活动中的网站Corobizar.com的应用程序,并在第二个活动中看到一个流,我知道该怎么做但当我尝试启动第二个活动时应用崩溃 这是清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="arceos.com.corobizartv">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
    android:allowBackup="true"
    android:icon="@mipmap/logomini"
    android:label="@string/app_name"
    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 android:label="@string/app_name" android:name=".SecondActivity"/>
    </activity>
</application>
</manifest>

这是mainActivity的代码:

package arceos.com.corobizartv;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;


public class MainActivity extends AppCompatActivity {

String url = "corobizar.com";
Button login;
EditText UserNom;
EditText PassMot;
String Username = "";
String Password = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    login = (Button) findViewById(R.id.login);
    login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            UserNom = (EditText) findViewById(R.id.NomUser);
            Username = UserNom.getText().toString();
            PassMot = (EditText) findViewById(R.id.PassMot);
            Password = PassMot.getText().toString();
            new Title().execute();
        }
    });
    Intent intent = getIntent();
    String value = intent.getStringExtra("key"); //if it's a string you stored.

}

public class Title extends AsyncTask<Void, Void, Void> {
    protected Void doInBackground(Void... arg0) {
        try {
            Document document = Jsoup.connect(url)
                    .data("username", Username, "password", Password)
                    .timeout(60000)
                    .userAgent("Mozilla")
                    .post();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    protected void onPostExecute(Void result) {
        Intent intent = new Intent(MainActivity.this, SecondActivity.class);
        startActivity(intent);
        }

    }

}

这是布局mainActivity:              

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true">


    <EditText
        android:layout_width="match_parent"
        android:layout_height="69dp"
        android:id="@+id/NomUser"
        android:layout_gravity="center_horizontal|top"
        android:hint="Username"
        android:inputType="text"
        android:maxLines="1"
        android:singleLine="true" />

    <EditText
        android:id="@+id/PassMot"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeActionId="@+id/login"
        android:imeOptions="actionUnspecified"
        android:layout_gravity="center"
        android:inputType="textPassword"
        android:maxLines="1"
        android:singleLine="true"
        android:hint="Password"/>

    <Button
        android:layout_width="248dp"
        android:layout_height="wrap_content"
        android:text="Connecte-toi"
        android:id="@+id/login"
        android:layout_gravity="center_horizontal|bottom"
        android:onClick="sendMessage"/>

</FrameLayout>
</RelativeLayout>

这是logcat:

  

05-30 22:05:33.714 21863-21863 / arceos.com.corobizartv   E / AndroidRuntime:致命异常:主要                                                                           流程:arceos.com.corobizartv,PID:21863                                                                           android.content.ActivityNotFoundException:无法找到显式   活动课   {arceos.com.corobizartv / arceos.com.corobizartv.SecondActivity};有   你在AndroidManifest.xml中声明了这个活动?                                                                               在   android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1761)                                                                               在   android.app.Instrumentation.execStartActivity(Instrumentation.java:1485)                                                                               在android.app.Activity.startActivityForResult(Activity.java:3821)                                                                               在android.app.Activity.startActivityForResult(Activity.java:3782)                                                                               在   android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:843)                                                                               在android.app.Activity.startActivity(Activity.java:4092)                                                                               在android.app.Activity.startActivity(Activity.java:4060)                                                                               在   arceos.com.corobizartv.MainActivity $ Title.onPostExecute(MainActivity.java:80)                                                                               在   arceos.com.corobizartv.MainActivity $ Title.onPostExecute(MainActivity.java:62)                                                                               在android.os.AsyncTask.finish(AsyncTask.java:632)                                                                               在android.os.AsyncTask.access $ 600(AsyncTask.java:177)                                                                               在android.os.AsyncTask $ InternalHandler。

     

的handleMessage(AsyncTask.java:645)                                                                               在android.os.Handler.dispatchMessage(Handler.java:102)                                                                               在android.os.Looper.loop(Looper.java:135)                                                                               在android.app.ActivityThread.main(ActivityThread.java:5289)                                                                               at java.lang.reflect.Method.invoke(Native Method)                                                                               在java.lang.reflect.Method.invoke(Method.java:372)                                                                               在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)                                                                               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)05-30   22:05:35.671 21863-21863 / arceos.com.corobizartv I / Process:发送   信号。 PID:21863 SIG:9

再见

1 个答案:

答案 0 :(得分:1)

<activity android:label="@string/app_name" android:name=".SecondActivity"/><activity>标记内定义。必须在外面宣布:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="arceos.com.corobizartv">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
    android:allowBackup="true"
    android:icon="@mipmap/logomini"
    android:label="@string/app_name"
    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:label="@string/app_name" android:name=".SecondActivity"/>
</application>
</manifest>