错误移动数据从一个活动到另一个活动

错误移动数据从一个活动到另一个活动

本文介绍了错误移动数据从一个活动到另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一些数据从一个活动到另一个。
使用类应用程序

I am trying To Move Some Data From One Activity To another one.Using Class Application

项目活动:


  • Main_Activity。

  • Main_Activity.

Second_Activity。

Second_Activity.

主要活动code

public class MainActivity extends Activity
{
    private ApplicationSettings application;
    private Button btn;
    private EditText txt1;
    private EditText txt2;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txt1 = (EditText)findViewById(R.id.txt1);
        txt2 = (EditText)findViewById(R.id.txt2);
        btn = (Button)findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View arg0)
            {
                application = (ApplicationSettings)getApplication();
                application.setUserID(txt1.getText().toString());
                application.setUserName(txt2.getText().toString());
                Intent intent = new Intent(MainActivity.this,SecondActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

=============================
第二项活动code

=============================Second Activity Code

public class SecondActivity extends Activity
{

    private ApplicationSettings application;
    private TextView txt1,txt2;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

           application = (ApplicationSettings)getApplication();

           txt1 = (TextView)findViewById(R.id.txt1);
           txt2 = (TextView)findViewById(R.id.txt2);

           txt1.setText(application.getUserID().toString());
           txt2.setText(application.getUserName().toString());
    }
}

==============================
应用类

==============================Application Class

public class ApplicationSettings extends Application
{


    String UserID;
    String UserName;

    public String getUserID()
    {
        return UserID;
    }
    public void setUserID(String userID)
    {
        UserID = userID;
    }
    public String getUserName()
    {
        return UserName;
    }
    public void setUserName(String userName)
    {
        UserName = userName;
    }

    @Override
    public void onCreate() {
        super.onCreate();

    }
}

=============================

=============================

LogCat中

11-25 15:32:31.695: E/Trace(17282): error opening trace file: No such file or directory (2)
11-25 15:32:31.960: D/libEGL(17282): loaded /system/lib/egl/libEGL_mali.so
11-25 15:32:31.965: D/libEGL(17282): loaded /system/lib/egl/libGLESv1_CM_mali.so
11-25 15:32:31.965: D/libEGL(17282): loaded /system/lib/egl/libGLESv2_mali.so
11-25 15:32:31.975: D/(17282): Device driver API match
11-25 15:32:31.975: D/(17282): Device driver API version: 10
11-25 15:32:31.975: D/(17282): User space API version: 10
11-25 15:32:31.975: D/(17282): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Wed Sep 12 17:53:53 KST 2012
11-25 15:32:32.000: D/OpenGLRenderer(17282): Enabling debug mode 0
11-25 15:32:32.005: E/SensorManager(17282): thread start
11-25 15:32:32.010: D/SensorManager(17282): registerListener :: handle = 0  name= LSM330DLC Acceleration Sensor delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41f68078
11-25 15:32:32.075: W/IInputConnectionWrapper(17282): showStatusIcon on inactive InputConnection
11-25 15:32:37.290: D/GestureDetector(17282): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
11-25 15:32:37.295: D/SensorManager(17282): unregisterListener::  Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41f68078
11-25 15:32:37.295: D/Sensors(17282): Remain listener = Sending .. normal delay 200ms
11-25 15:32:37.295: I/Sensors(17282): sendDelay --- 200000000
11-25 15:32:37.295: D/SensorManager(17282): JNI - sendDelay
11-25 15:32:37.295: I/SensorManager(17282): Set normal delay = true
11-25 15:32:37.300: D/SensorManager(17282): registerListener :: handle = 0  name= LSM330DLC Acceleration Sensor delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41f69650
11-25 15:32:37.315: W/IInputConnectionWrapper(17282): getSelectedText on inactive InputConnection
11-25 15:32:37.315: W/IInputConnectionWrapper(17282): setComposingText on inactive InputConnection
11-25 15:32:37.315: W/IInputConnectionWrapper(17282): getExtractedText on inactive InputConnection
11-25 15:32:41.350: D/SensorManager(17282): unregisterListener::  Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41f69650
11-25 15:32:41.350: D/Sensors(17282): Remain listener = Sending .. normal delay 200ms
11-25 15:32:41.350: I/Sensors(17282): sendDelay --- 200000000
11-25 15:32:41.350: D/SensorManager(17282): JNI - sendDelay
11-25 15:32:41.350: I/SensorManager(17282): Set normal delay = true
11-25 15:32:41.620: W/IInputConnectionWrapper(17282): showStatusIcon on inactive InputConnection
11-25 15:32:46.200: D/SensorManager(17282): registerListener :: handle = 0  name= LSM330DLC Acceleration Sensor delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41f8b4c8
11-25 15:32:47.170: D/GestureDetector(17282): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
11-25 15:32:47.175: D/SensorManager(17282): unregisterListener::  Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41f8b4c8
11-25 15:32:47.175: D/Sensors(17282): Remain listener = Sending .. normal delay 200ms
11-25 15:32:47.175: I/Sensors(17282): sendDelay --- 200000000
11-25 15:32:47.175: D/SensorManager(17282): JNI - sendDelay
11-25 15:32:47.175: I/SensorManager(17282): Set normal delay = true
11-25 15:32:47.180: D/SensorManager(17282): registerListener :: handle = 0  name= LSM330DLC Acceleration Sensor delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41f8c6b8
11-25 15:32:47.210: W/IInputConnectionWrapper(17282): getSelectedText on inactive InputConnection
11-25 15:32:47.210: W/IInputConnectionWrapper(17282): setComposingText on inactive InputConnection
11-25 15:32:47.210: W/IInputConnectionWrapper(17282): getExtractedText on inactive InputConnection
11-25 15:32:50.470: D/GestureDetector(17282): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
11-25 15:32:50.475: D/SensorManager(17282): unregisterListener::  Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41f8c6b8
11-25 15:32:50.475: D/Sensors(17282): Remain listener = Sending .. normal delay 200ms
11-25 15:32:50.475: I/Sensors(17282): sendDelay --- 200000000
11-25 15:32:50.475: D/SensorManager(17282): JNI - sendDelay
11-25 15:32:50.475: I/SensorManager(17282): Set normal delay = true
11-25 15:32:50.480: D/SensorManager(17282): registerListener :: handle = 0  name= LSM330DLC Acceleration Sensor delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41f8b4c8
11-25 15:32:50.490: W/IInputConnectionWrapper(17282): getSelectedText on inactive InputConnection
11-25 15:32:50.490: W/IInputConnectionWrapper(17282): setComposingText on inactive InputConnection
11-25 15:32:50.490: W/IInputConnectionWrapper(17282): getExtractedText on inactive InputConnection
11-25 15:32:53.000: D/GestureDetector(17282): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 3 mFalseSizeCnt:0
11-25 15:32:53.160: D/AndroidRuntime(17282): Shutting down VM
11-25 15:32:53.160: W/dalvikvm(17282): threadid=1: thread exiting with uncaught exception (group=0x412862a0)
11-25 15:32:53.175: E/AndroidRuntime(17282): FATAL EXCEPTION: main
11-25 15:32:53.175: E/AndroidRuntime(17282): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test01/com.example.test01.SecondActivity}: java.lang.NullPointerException
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.os.Looper.loop(Looper.java:137)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.app.ActivityThread.main(ActivityThread.java:4898)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at java.lang.reflect.Method.invokeNative(Native Method)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at java.lang.reflect.Method.invoke(Method.java:511)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at dalvik.system.NativeStart.main(Native Method)
11-25 15:32:53.175: E/AndroidRuntime(17282): Caused by: java.lang.NullPointerException
11-25 15:32:53.175: E/AndroidRuntime(17282):    at com.example.test01.SecondActivity.onCreate(SecondActivity.java:26)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.app.Activity.performCreate(Activity.java:5191)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
11-25 15:32:53.175: E/AndroidRuntime(17282):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
11-25 15:32:53.175: E/AndroidRuntime(17282):    ... 11 more
11-25 15:32:53.195: D/dalvikvm(17282): GC_CONCURRENT freed 180K, 9% free 12405K/13575K, paused 12ms+2ms, total 31ms


我需要在主要活动传递数据从DditTexts在Second_activity TextView的


I need To Pass Data From the DditTexts on the main activity to the TextView in Second_activity

在此先感谢

问候

推荐答案

随着你的日志为:

有你在你的Andr​​oidManifest.xml宣布这项活动?

意味着确保你已经宣布AndroidManifest SecondActivity.class 活动为:

means make sure you have declared SecondActivity.class activity in AndroidManifest as :

<Activity android:name=".SecondActivity" />

如果您已声明则确保它在同一个包或者你的 SecondActivity.java

if you have declared it then make sure it's in same package or have same name as you have created in SecondActivity.java

如果您有 SecondActivity 在不同的包,那么其声明中AndroidManifest为:

if you have SecondActivity in different Package then declare it in AndroidManifest as :

<Activity android:name="<FULL_PACKAGE_NAME>.SecondActivity" />

这篇关于错误移动数据从一个活动到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:51