>

두 가지 활동이 있습니다. 하나는 MainActivity이고 다른 하나는 Main2Activity입니다. Main2Activity에서 TextView의 사용자로부터 입력을 받아 ArrayList에 저장합니다.이 ArrayList를 MainActivity로 보내면 사용자에게 표시합니다. 나는 의도를 사용했다. 그러나 내 앱이 다운되었습니다. 아래는 두 가지 활동 코드입니다. 유지 보수

   package com.example.to_doapp;
   import android.content.Intent;
   import android.os.Bundle;
   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.view.View;
   import android.view.Menu;
   import android.view.MenuItem;
   import android.widget.LinearLayout;
   import android.widget.TextView;
   import android.widget.Toast;
   import java.io.Serializable;
   import java.util.ArrayList;
   public class MainActivity extends AppCompatActivity {
   public void onclick (View view  )
   {
        Intent intent = new Intent(getApplicationContext(), 
            Main2Activity.class );
        startActivity(intent);
  }
@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
    Intent intent = getIntent();
    //Toast.makeText (this,intent.getStringExtra("task"), Toast.LENGTH_SHORT ).show() ;
    Bundle args = intent.getBundleExtra("BUNDLE");
     ArrayList< String> object  =  (ArrayList<String>) args.getSerializable("ARRAYLIST");
    LinearLayout lView = new LinearLayout(this);
    TextView myText= new TextView(this);
    lView.addView(myText);
    for (int i=0; i<object.size();i++){
        myText.append(object.get(i));
        myText.append("\n");
    }
    setContentView(lView);
 }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;       }
    return super.onOptionsItemSelected(item);
  }
  }

Main2Activity는         com.example.to_doapp 패키지;

   import android.content.Intent;
    import android.os.Bundle;
    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.view.View;
    import android.widget.EditText;
    import java.io.Serializable;
    import java.util.ArrayList;
    public class Main2Activity extends AppCompatActivity {
    ArrayList< String> arr = new ArrayList < String > ();
    public void BackMain ( View view )
    {
        Intent intent = new Intent( getApplicationContext() 
           ,MainActivity.class ) ;
       Bundle args = new Bundle();
        EditText editText = ( EditText) findViewById( R.id.editText3) ;
        String s = editText.getText().toString();
       arr.add ( s ) ;
       args.putSerializable("ARRAYLIST",(Serializable)arr);
        intent.putExtra("bundle",args);
       startActivity(intent);
     }
   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        FloatingActionButton fab = findViewById(R.id.fab);
         fab.setOnClickListener(new View.OnClickListener() {
         @Override
        public void onClick(View view) {
        Snackbar.make(view, "Replace with your own action", 
            Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
       });
       }
       }

내 Logcat은 이와 비슷한 것을 보여줍니다

03-21 07:55:00.407 763-826/? E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ id=81, legacyType=-1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED] ] 03-21 07:55:58.292 29529-29529/? E/MPlugin: Unsupported class: com.mediatek.common.telephony.IOnlyOwnerSimSupport 03-21 07:56:01.380 29645-29672/? E/MPlugin: Unsupported class: com.mediatek.common.telephony.IOnlyOwnerSimSupport 03-21 07:56:01.577 29624-29624/com.example.to_doapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.to_doapp, PID: 29624 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.to_doapp/com.example.to_doapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.Serializable android.os.Bundle.getSerializable(java.lang.String)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614) at android.app.ActivityThread.access$800(ActivityThread.java:178) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5643) 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:960) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.Serializable android.os.Bundle.getSerializable(java.lang.String)' on a null object reference at com.example.to_doapp.MainActivity.onCreate(MainActivity.java:51) at android.app.Activity.performCreate(Activity.java:6100) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614)  at android.app.ActivityThread.access$800(ActivityThread.java:178)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)  at android.os.Handler.dispatchMessage(Handler.java:111)  at android.os.Looper.loop(Looper.java:194)  at android.app.ActivityThread.main(ActivityThread.java:5643)  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:960)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)  03-21 07:56:01.787 29645-29670/? E/WifiManager: mWifiServiceMessenger == null 03-21 07:56:03.275 29764-29764/? E/MPlugin: Unsupported class: com.mediatek.common.telephony.IOnlyOwnerSimSupport 03-21 07:56:03.390 29645-29671/? E/NativeCrypto: ssl=0xb47ac800 cert_verify_callback x509_store_ctx=0x9fa343e0 arg=0x0 03-21 07:56:03.390 29645-29671/? E/NativeCrypto: ssl=0xb47ac800 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_ECDSA 03-21 07:56:03.536 29645-29672/? E/NativeCrypto: ssl=0xaf83da00 cert_verify_callback x509_store_ctx=0x9f930460 arg=0x0 03-21 07:56:03.536 29645-29672/? E/NativeCrypto: ssl=0xaf83da00 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_ECDSA 03-21 07:56:03.584 29787-29787/? E/WifiManager: mWifiServiceMessenger == null 03-21 07:56:04.382 29787-29787/? E/MPlugin: Unsupported class: com.mediatek.common.telephony.IOnlyOwnerSimSupport 03-21 07:56:04.743 29838-29838/? E/MPlugin: Unsupported class: com.mediatek.common.telephony.IOnlyOwnerSimSupport 03-21 07:56:11.598 29645-29681/? E/Finsky: [4373] fng.a(20): Unable to build selector: /storage/sdcard0/Download/marketenvs.csv: open failed: ENOENT (No such file or directory) 03-21 07:56:11.772 29645-29724/? E/SQLiteLog: (283) recovered 63 frames from WAL file /data/data/com.android.vending/databases/phenotype.db-wal 03-21 07:56:55.470 763-763/? E/WifiTrafficPoller: ENABLE_TRAFFIC_STATS_POLL false Token 226 03-21 07:56:55.535 763-823/? E/WifiStateMachine: ScanModeState (when=-58ms what=131167!CMD_SCREEN_STATE_CHANGED{ when=-58ms what=131167 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.536 763-823/? E/WifiStateMachine: DriverStartedState (when=-58ms what=131167!CMD_SCREEN_STATE_CHANGED{ when=-58ms what=131167 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.536 763-823/? E/WifiStateMachine: SupplicantStartedState (when=-59ms what=131167!CMD_SCREEN_STATE_CHANGED{ when=-59ms what=131167 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.537 763-823/? E/WifiStateMachine: DefaultState (when=-60ms what=131167!CMD_SCREEN_STATE_CHANGED{ when=-60ms what=131167 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.547 763-823/? E/WifiStateMachine: cancelDelayedScan ->228 03-21 07:56:55.547 763-823/? E/WifiStateMachine: handleScreenStateChanged Exit: false 03-21 07:56:55.548 763-823/? E/WifiStateMachine: ScanModeState (when=-4ms what=131154CMD_ENABLE_RSSI_POLL{ when=-4ms what=131154 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.550 763-823/? E/WifiStateMachine: DriverStartedState (when=-6ms what=131154CMD_ENABLE_RSSI_POLL{ when=-6ms what=131154 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.550 763-823/? E/WifiStateMachine: SupplicantStartedState (when=-6ms what=131154CMD_ENABLE_RSSI_POLL{ when=-6ms what=131154 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.551 763-823/? E/WifiStateMachine: DefaultState (when=-6ms what=131154CMD_ENABLE_RSSI_POLL{ when=-7ms what=131154 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.551 763-823/? E/WifiStateMachine: ScanModeState (when=-6ms what=131158 arg1=1CMD_SET_SUSPEND_OPT_ENABLED{ when=-6ms what=131158 arg1=1 target=com.android.internal.util.StateMachine$SmHandler } 1 0 03-21 07:56:55.552 763-823/? E/WifiStateMachine: DriverStartedState (when=-7ms what=131158 arg1=1CMD_SET_SUSPEND_OPT_ENABLED{ when=-7ms what=131158 arg1=1 target=com.android.internal.util.StateMachine$SmHandler } 1 0 03-21 07:56:55.574 763-823/? E/WifiStateMachine: setSuspendOptimizationsNative: 4 true -want true stack:setSuspendOptimizationsNative - access$16400 - processMessage - processMsg 03-21 07:56:55.575 763-823/? E/WifiStateMachine: setSuspendOptimizationsNative do it 4 true stack:setSuspendOptimizationsNative - access$16400 - processMessage - processMsg 03-21 07:56:55.585 763-823/? E/native: do suspend true 03-21 07:56:55.599 763-823/? E/WifiStateMachine: ScanModeState (when=-53ms what=131248M_CMD_NOTIFY_SCREEN_OFF{ when=-53ms what=131248 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.599 763-823/? E/WifiStateMachine: DriverStartedState (when=-54ms what=131248M_CMD_NOTIFY_SCREEN_OFF{ when=-54ms what=131248 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.600 763-823/? E/WifiStateMachine: SupplicantStartedState (when=-54ms what=131248M_CMD_NOTIFY_SCREEN_OFF{ when=-55ms what=131248 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:55.601 763-823/? E/WifiStateMachine: DefaultState (when=-55ms what=131248M_CMD_NOTIFY_SCREEN_OFF{ when=-55ms what=131248 target=com.android.internal.util.StateMachine$SmHandler } 0 0 03-21 07:56:56.504 1773-29908/? E/MPlugin: Unsupported class: com.mediatek.common.telephony.IOnlyOwnerSimSupport 03-21 07:56:56.635 763-779/? E/Sensors: handleToDriver handle(0) 03-21 07:56:56.636 763-779/? E/Sensors: handleToDriver handle(0) 03-21 07:56:56.638 763-779/? E/Sensors: new setDelay handle(0),ns(20000000)m, error(0), index(2) 03-21 07:57:00.388 763-1406/? E/Sensors: handleToDriver handle(0) 03-21 07:57:28.639 1673-13747/? E/WakeLock: GCM_HB_ALARM release without a matched acquire!

  • 답변 # 1

    로그에서 앱이 다운되었습니다 :

    와이즈 비즈

    당신의 방법으로

    java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.Serializable android.os.Bundle.getSerializable(java.lang.String)' on a null object reference at com.example.to_doapp.MainActivity.onCreate(MainActivity.java:51)

    Main2Activity에서 (Java 이름 지정 규칙에 따라 메소드 이름을 "backMain"으로 바꾸는 것이 좋습니다) public void BackMain ( View view )  여기서 첫 번째 인수 인 추가 데이터의 키 (또는 이름)는 "번들"입니다. 그러나 MainActivity 에서이 추가 데이터를 얻으면 intent.putExtra("bundle",args); 가 있습니다.  여기서 번들 이름은 "BUNDLE"이며 "bundle"과 일치하지 않으므로 null을 반환합니다. 추가 데이터에 동일한 이름을 사용해야합니다 (이 경우에는 Bundle args = intent.getBundleExtra("BUNDLE"); ). )를 사용하여 한 Activity에서 다른 Activity로 Intent를 전달하려고합니다.

  • 답변 # 2

    arrayList 객체를 다른 활동으로 전달하려면이 코드를 사용하십시오.

    Main2Activity에서

    Bundle
    
    

    주요 활동에서

    ArrayList<String> arr = new ArrayList<String>();
    EditText editText = ( EditText) findViewById( R.id.editText3) ;
    String s = editText.getText().toString();
    arr.add (s) ;
    intent.putExtra("mylist", arr);
    
    
    ArrayList<String> object = (ArrayList<String>)getIntent().getSerializableExtra("mylist");

  • 이전 r - dplyr을 사용하여 각 그룹에 대해 동일한 수의 보간 점을 사용하여 데이터 프레임에서 그룹화 된 데이터를 확장하고 보간하는 방법은 무엇입니까?
  • 다음 css - 반응에 배경 이미지 설정