Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 应用程序在avd上运行正常,但在实际设备上运行不正常_Javascript_Android_Avd - Fatal编程技术网

Javascript 应用程序在avd上运行正常,但在实际设备上运行不正常

Javascript 应用程序在avd上运行正常,但在实际设备上运行不正常,javascript,android,avd,Javascript,Android,Avd,我对android有点陌生,实际上这是我的第一个应用。该应用程序未通过完成,我想测试UI,它在AVD上工作正常,但当我将.apk文件从bin文件夹复制到手机时,它安装正常,但无法工作,最终导致强制关闭错误。我不知道问题出在哪里,我在另一篇文章中看到了关于解析edittext中的内容,我拿出布局,再次运行,但仍然不起作用。再说一次,我是新手,请帮帮我 Mainactivity.java package com.example.studentapp; import java.util.ArrayLi

我对android有点陌生,实际上这是我的第一个应用。该应用程序未通过完成,我想测试UI,它在AVD上工作正常,但当我将.apk文件从bin文件夹复制到手机时,它安装正常,但无法工作,最终导致强制关闭错误。我不知道问题出在哪里,我在另一篇文章中看到了关于解析edittext中的内容,我拿出布局,再次运行,但仍然不起作用。再说一次,我是新手,请帮帮我

Mainactivity.java

package com.example.studentapp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;

import com.example.studentapp.ExpandableListAdapter;

import android.widget.Toast;

 public class MainActivity extends ActionBarActivity {

    DrawerLayout mDrawerLayout;
    ExpandableListView mDrawerList;
    ExpandableListAdapter listAdapter;
    List<String> listDataHeader;
    HashMap<String, List<String>> listDataChild;
    private ActionBarDrawerToggle actionBarDrawerToggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getfragment(125);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ExpandableListView) findViewById(R.id.left_drawer);



            // preparing list data
            prepareListData();

            listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

            // setting list adapter
            mDrawerList.setAdapter(listAdapter);

            mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
            actionBarDrawerToggle = new ActionBarDrawerToggle(
                    this,                  /* host Activity */
                    mDrawerLayout,         /* DrawerLayout object */
                    R.drawable.ic_drawer,  /* nav drawer icon to replace 'Up' caret */
                    R.string.drawer_open,  /* "open drawer" description */
                    R.string.drawer_close  /* "close drawer" description */
                    );

            // 2.2 Set actionBarDrawerToggle as the DrawerListener
           mDrawerLayout.setDrawerListener(actionBarDrawerToggle);

            // 2.3 enable and show "up" arrow
            getActionBar().setDisplayHomeAsUpEnabled(true); 

            // Listview Group click listener
            mDrawerList.setOnGroupClickListener(new OnGroupClickListener() {

                @Override
                public boolean onGroupClick(ExpandableListView parent, View v,
                        int groupPosition, long id) {
                     Toast.makeText(getApplicationContext(),
                     "Group Clicked " + (groupPosition),
                     Toast.LENGTH_SHORT).show();

                     //return true for non collapsable items, and false for collapsable items.
                     if(groupPosition==1 || groupPosition==2)
                     { // getfragment(groupPosition);
                     getActionBar().setTitle(listDataHeader.get(groupPosition));
                    return true;}
                     else
                         return false;
                }
            });

            // Listview Group expanded listener
            mDrawerList.setOnGroupExpandListener(new OnGroupExpandListener() {

                @Override
                public void onGroupExpand(int groupPosition) {
                    Toast.makeText(getApplicationContext(),
                            listDataHeader.get(groupPosition) + " Expanded",
                            Toast.LENGTH_SHORT).show();
                }
            });

            // Listview Group collasped listener
            mDrawerList.setOnGroupCollapseListener(new OnGroupCollapseListener() {

                @Override
                public void onGroupCollapse(int groupPosition) {
                    Toast.makeText(getApplicationContext(),
                            listDataHeader.get(groupPosition) + " Collapsed",
                            Toast.LENGTH_SHORT).show();

                }
            });

            // Listview on child click listener
            mDrawerList.setOnChildClickListener(new OnChildClickListener() {

                public boolean onChildClick(ExpandableListView parent, View v,
                        int groupPosition, int childPosition, long id) {
                    // TODO Auto-generated method stub
                    Toast.makeText(
                            getApplicationContext(),
                            listDataHeader.get(groupPosition)
                                    + " : "
                                    + listDataChild.get(
                                            listDataHeader.get(groupPosition)).get(
                                            childPosition), Toast.LENGTH_SHORT)
                            .show();

                    getActionBar().setTitle(listDataChild.get(
                            listDataHeader.get(groupPosition)).get(
                            childPosition));

                    return false;
                }
            });







        }

    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
         actionBarDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        actionBarDrawerToggle.onConfigurationChanged(newConfig);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

         // call ActionBarDrawerToggle.onOptionsItemSelected(), if it returns true
        // then it has handled the app icon touch event

        if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    private void prepareListData() {
        listDataHeader = new ArrayList<String>();
        listDataChild = new HashMap<String, List<String>>();

        // Adding header data
        listDataHeader.add("Center Details");

        // Adding child data
        List<String> CentDet = new ArrayList<String>();
        CentDet.add("Study Center");
        CentDet.add("Information Center");
        CentDet.add("Overseas Center");
        listDataHeader.add("Login");
        listDataHeader.add("PCP Schedule");
        listDataHeader.add("Course");
        List<String> courseS = new ArrayList<String>();
        courseS.add("Study Materials");
        courseS.add("Syllabus");


        listDataHeader.add("Exam");
        List<String> Exams = new ArrayList<String>();
        Exams.add("Hall Ticket");
        Exams.add("Exam Venue");
        Exams.add("Exam Schedule");
        Exams.add("Practical Schedule");
        Exams.add("Model Question Papers");

listDataHeader.add("Results");
List<String> Resultss= new ArrayList<String>();
Resultss.add("Regular Stream");
Resultss.add("Overseas");
        listDataChild.put(listDataHeader.get(0), CentDet); // Header, Child data
        listDataChild.put(listDataHeader.get(1), null);
        listDataChild.put(listDataHeader.get(2), null);
        listDataChild.put(listDataHeader.get(3), courseS);
        listDataChild.put(listDataHeader.get(4), Exams);
        listDataChild.put(listDataHeader.get(5), Resultss);

    }




  void getfragment(int x)
  {
      android.app.FragmentManager fragmentManager1 = getFragmentManager();
        android.app.FragmentTransaction fragmentTransaction1 = fragmentManager1.beginTransaction();
    fragmenttwo lm_fragment = new fragmenttwo();
    switch (x)
    {

 //     case 1:
  //    lm_fragment.fragmenttwoo(1);
  //    
    //break;

    case 2:
        lm_fragment.fragmenttwoo(2);

    break;

    case 3:
        lm_fragment.fragmenttwoo(3);
    break;



    case 125:
        lm_fragment.fragmenttwoo(125);
        break;

    }       
        fragmentTransaction1.replace(R.id.content_frame, lm_fragment);
        fragmentTransaction1.commit();

    }


}
expandableListaData.java

    package com.example.studentapp;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private Context _context;
    private List<String> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<String, List<String>> _listDataChild;

    public ExpandableListAdapter(Context context, List<String> listDataHeader,
            HashMap<String, List<String>> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
    }

    @Override
    public Object getChild(int groupPosition, int childPosititon) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .get(childPosititon);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.lblListItem);

        txtListChild.setText(childText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return this._listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        String headerTitle = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_group, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.lblListHeader);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

}

读取第223行的logcat:noSuchMethodError。双击logcat中的该行,您将在MainActivity的第223行结束。告诉我们密码

那个国家不是德国吗


或者您正在不知道getActionBar()的设备上运行。

为什么不使用?在LogCat中,您应该找到导致崩溃的原因以及导致崩溃的行号。这里有一篇博客文章展示了如何调试应用程序崩溃:@AndyRes,OP需要首先通过ADB将设备连接到系统。
当我将.apk文件从bin文件夹复制到手机时,
这不是调试应用程序的正常方式。通常情况下,您会使用usb电缆将手机连接到pc。然后在Eclipse中,您会右键单击应用程序文件夹并选择
Run As | Android应用程序
Eclipse会在您的手机上安装应用程序并运行它。你试过了吗?这就是其他人使用adb调用的
。我通过导入support.v4.app.ActionBar解决了getActionBar()问题,并将其更改为getSupportActionBar()。现在我在fragmenttransaction上的替换方法上遇到问题,我还导入了…v4.fragmenttransaction。它说“FragmentTransaction类型中的方法replace(int,Fragment)不适用于参数(int,fragmenttwo)”,尝试找出它需要什么参数以及属于哪种类型。Eclipse会在您输入的时候告诉您。before.replace()。
    package com.example.studentapp;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private Context _context;
    private List<String> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<String, List<String>> _listDataChild;

    public ExpandableListAdapter(Context context, List<String> listDataHeader,
            HashMap<String, List<String>> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
    }

    @Override
    public Object getChild(int groupPosition, int childPosititon) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .get(childPosititon);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.lblListItem);

        txtListChild.setText(childText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return this._listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        String headerTitle = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_group, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.lblListHeader);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

}
06-03 21:18:03.789: W/dalvikvm(11126): VFY: unable to resolve virtual method 8281: Lcom/example/studentapp/MainActivity;.getFragmentManager ()Landroid/app/FragmentManager;
06-03 21:18:03.789: D/dalvikvm(11126): VFY: replacing opcode 0x6e at 0x0000
06-03 21:18:03.789: D/dalvikvm(11126): VFY: dead code 0x0003-0029 in Lcom/example/studentapp/MainActivity;.getfragment (I)V
06-03 21:18:03.812: W/dalvikvm(11126): VFY: unable to resolve virtual method 8279: Lcom/example/studentapp/MainActivity;.getActionBar ()Landroid/app/ActionBar;
06-03 21:18:03.812: D/dalvikvm(11126): VFY: replacing opcode 0x6e at 0x005b
06-03 21:18:03.812: D/dalvikvm(11126): VFY: dead code 0x005e-008b in Lcom/example/studentapp/MainActivity;.onCreate (Landroid/os/Bundle;)V
06-03 21:18:03.820: I/ApplicationPackageManager(11126): cscCountry is not German : INS
06-03 21:18:03.976: D/AndroidRuntime(11126): Shutting down VM
06-03 21:18:03.976: W/dalvikvm(11126): threadid=1: thread exiting with uncaught exception (group=0x40018578)
06-03 21:18:03.976: E/AndroidRuntime(11126): FATAL EXCEPTION: main
06-03 21:18:03.976: E/AndroidRuntime(11126): java.lang.NoSuchMethodError: com.example.studentapp.MainActivity.getFragmentManager
06-03 21:18:03.976: E/AndroidRuntime(11126):    at com.example.studentapp.MainActivity.getfragment(MainActivity.java:223)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at com.example.studentapp.MainActivity.onCreate(MainActivity.java:42)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at android.os.Looper.loop(Looper.java:130)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at android.app.ActivityThread.main(ActivityThread.java:3687)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at java.lang.reflect.Method.invokeNative(Native Method)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at java.lang.reflect.Method.invoke(Method.java:507)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-03 21:18:03.976: E/AndroidRuntime(11126):    at dalvik.system.NativeStart.main(Native Method)