Android不会加载新活动

时间:2016-11-19 11:38:50

标签: android

我正在尝试通过按钮点击在新活动中加载XML中的数据。问题是,当我点击按钮时没有真正发生。它没有崩溃,应用程序只是变得没有响应,这就是全部。它不会进入下一个活动。有什么想法吗?

主要活动:

 public void onSignupSuccess() {
        _signupButton.setEnabled(true);
        setResult(RESULT_OK, null);
        String toSend = "mailto:" + _nameText.getText().toString();
        String email = _emailText.getText().toString();
        String[] toArr = {email};
        try {
            if(sendEmail()) {
                Toast.makeText(this, "Email was sent successfully.", Toast.LENGTH_LONG).show();
                Intent myIntent = new Intent(MainActivity.this, ListItemsActivity.class);
                Log.d(TAG, "Trying to move to the next pane");
                startActivity(myIntent);
           } else {
                Toast.makeText(this, "Email was not sent.", Toast.LENGTH_LONG).show();
            }
        } catch(Exception e) {
            Log.e("MailApp", "Could not send email", e);
        }
    }

列出活动

public class ListItemsActivity extends Activity {
    ListView listView;
    private static final String TAG = "ListActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "Trying to create the list activitye");
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);


        //* *EDIT* *
        this.listView  = (ListView) findViewById(R.id.listView1);
}
}

我的列表活动

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_list_items"
    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.melisaam.logintest.ListItemsActivity">

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:entries="@array/sections" >
    </ListView>

</RelativeLayout>

array.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="sections">
        <item >Pro Constructive</item>
        <item >Con Constructive</item>
        <item >1st Speaker Cross</item>
        <item >Pro Rebbutal</item>
        <item >Con Rebuttal</item>
        <item >2nd Speaker Cross</item>
        <item >Pro Summary</item>
        <item >Con Summary</item>
        <item >Grand Cross</item>
        <item >Pro Final Focus</item>
        <item >Con Final Focus</item>
    </string-array>
</resources>

我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.melisaam.logintest">

    <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=".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=".ListItemsActivity" />
        <activity android:name=".SingleListItem"></activity>
    </application>

</manifest>

这是我的日志。我无法做出任何改变。

D/ListActivity: Trying to create the list activitye
D/TextView: setTypeface with style : 0
D/Activity: performCreate Call Injection manager
I/InjectionManager: dispatchOnViewCreated > Target : com.example.melisaam.logintest.ListItemsActivity isFragment :false
D/SecWifiDisplayUtil: Metadata value : SecSettings2
D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{64e0b62 I.E...... R.....ID 0,0-0,0}
V/RenderScript: 0x7f613b7000 Launching thread(s), CPUs 8
D/mali_winsys: new_window_surface returns 0x3000,  [1440x2560]-format:1
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@dafc17b time:249820080
V/ActivityThread: updateVisibility : ActivityRecord{3c16e43 token=android.os.BinderProxy@2687817 {com.example.melisaam.logintest/com.example.melisaam.logintest.MainActivity}} show : false
D/ViewRootImpl: #3 mView = null

我不明白为什么它不起作用。我还需要做些什么吗?

编辑:

public boolean sendEmail() {
        try {
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.setType("plain/text");
            sendIntent.setData(Uri.parse("moismelisa@yahoo.com"));


sendIntent.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Registration Trucks for Sale");
String message = "I'd like to register on your site with the following information" + "\n" +
                "Username: " + _nameText.getText().toString() + "\n" +
                "Email: " + _emailText.getText().toString() + "\n" +
                "Password: " + _passwordText.getText().toString() + "\n" +
                "Thank you!";
        sendIntent.putExtra(Intent.EXTRA_TEXT, message);
        startActivity(sendIntent);
    } catch (Exception e) {
        return false;
    }
    return true;
}

在debug上,this.listView为null。所以这一行什么都不做:this.listView = (ListView) findViewById(R.id.listView1);

1 个答案:

答案 0 :(得分:2)

您已使用R.layout.activity_main作为ListItemsActivity中的布局。如果那是主要活动的布局,那就是问题

setContentView(R.layout.activity_main);