Android java.lang.InstantiationException:java.lang.Class不能在java.lang.Class.newInstance(本机方法)上实例化

Android java.lang.InstantiationException:java.lang.Class不能在java.lang.Class.newInstance(本机方法)上实例化,android,Android,我试图在我的小项目中添加一个带有评级栏和更多小部件的自定义对话框,但遇到了这个错误。这是一个初学者,如果你能让我简单一点,我会很高兴的,谢谢 我尝试将该类更改为抽象java类 package com.a.shon.scoutszone2; import android.app.Activity; import android.app.Dialog; import android.content.Intent; import android.graphics.

我试图在我的小项目中添加一个带有评级栏和更多小部件的自定义对话框,但遇到了这个错误。这是一个初学者,如果你能让我简单一点,我会很高兴的,谢谢

我尝试将该类更改为抽象java类

  package com.a.shon.scoutszone2;

    import android.app.Activity;
    import android.app.Dialog;
    import android.content.Intent;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ImageView;
    import android.widget.RatingBar;
    import android.widget.TextView;
    import android.widget.Toast;

    public  class ZoneActivity extends Activity implements View.OnClickListener  {

    Button btnPeula;
    ImageView ivMap;
    ImageView ivZone; //Will Change in the future
    //ListView lstZone;
    Zone current = new Zone();
    private Drawable[] maps;
    @Override
    protected void onCreate(Bundle savedInstanceState) { //add a dialog/menu to logout and manager activities
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zone);

        btnPeula = findViewById(R.id.btnPeula);
        ivMap = findViewById(R.id.ivMap);
        maps = new Drawable[4];
        maps[0] = getResources().getDrawable(R.drawable.map, null);
        ivMap.setImageDrawable(maps[0]);
        ivZone=findViewById(R.id.ivZone);//Will Change in the future
        maps[1] = getResources().getDrawable(R.drawable.tzone, null);//Will Change in the future
        ivZone.setImageDrawable(maps[1]); //Will Change in the future

        //lstZone = findViewById(R.id.lstZone);
        //lstZone.setOnItemClickListener(this);
        // lstZone.setAdapter( new ArrayAdapter<Zone>(this, android.R.layout))
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.the_menu,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(final MenuItem item)
    {
        super.onOptionsItemSelected(item);
        switch (item.getItemId())
        {
            case R.id.itemManager:
                Toast.makeText(this, "Manager...", Toast.LENGTH_SHORT).show();
                Intent manager = new Intent(this, manager.class);
                startActivity(manager);
                break;
            case R.id.itemLogout:
                Toast.makeText(this, "Logging out...", Toast.LENGTH_SHORT).show();
                finish();
                break;
            case R.id.itemRating: //make it a dialog not an activity!
                Toast.makeText(this, "Start Rating!", Toast.LENGTH_SHORT).show();
                showCustomDialog();
                break;
        }
        return true;
    }

    public void onPeula(View v)
    {
        Intent peula = new Intent(this, PeulotActivity.class);
        startActivity(peula);
    }

    private void showCustomDialog()
    {
        final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.custom_dialog);
        // set the custom dialog components - text, image and button
        final RatingBar mRatingbar = (RatingBar) findViewById(R.id.mRatingbar);
        final TextView tvRatingscale = (TextView) findViewById(R.id.tvRatingScale);
        final EditText etFeedback = (EditText) findViewById(R.id.etFeedback);
        Button btnSubmit = (Button) findViewById(R.id.btnSubmit);
        mRatingbar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
                tvRatingscale.setText(String.valueOf(v));
                switch ((int) ratingBar.getRating()) {
                    case 1:
                        tvRatingscale.setText("Very bad");
                        break;
                    case 2:
                        tvRatingscale.setText("Need some improvement");
                        break;
                    case 3:
                        tvRatingscale.setText("Good");
                        break;
                    case 4:
                        tvRatingscale.setText("Great");
                        break;
                    case 5:
                        tvRatingscale.setText("Awesome. I love it");
                        break;
                    default:
                        tvRatingscale.setText("");
                }
            }
        });
        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // if (etFeedback.getText().toString().isEmpty()) {
                //     Toast.makeText(ZoneActivity.this, "Please fill in feedback text box", Toast.LENGTH_LONG).show();
                // } else {
                etFeedback.setText("");
                mRatingbar.setRating(0);
                //Toast.makeText(ZoneActivity.this, "Thank you for sharing your feedback", Toast.LENGTH_SHORT).show();
            }
            // }
        });

        dialog.show();
    }


    @Override
    public void onClick(View v)
    {
        Toast.makeText(this, "Click", Toast.LENGTH_SHORT).show();
    }
}
package com.a.shon.scoutszone2;
导入android.app.Activity;
导入android.app.Dialog;
导入android.content.Intent;
导入android.graphics.drawable.drawable;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.MenuInflater;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ImageView;
导入android.widget.RatingBar;
导入android.widget.TextView;
导入android.widget.Toast;
公共类ZoneActivity扩展活动实现View.OnClickListener{
按钮btnPeula;
图像视图ivMap;
ImageView ivZone;//将在将来更改
//ListView区域;
区域当前=新区域();
私人可绘制[]地图;
@凌驾
受保护的void onCreate(Bundle savedInstanceState){//添加一个对话框/菜单以注销和管理活动
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zone);
btnPeula=findViewById(R.id.btnPeula);
ivMap=findViewById(R.id.ivMap);
地图=新的可绘制[4];
maps[0]=getResources().getDrawable(R.drawable.map,null);
ivMap.setImageDrawable(映射[0]);
ivZone=findviewbyd(R.id.ivZone);//将来会改变
maps[1]=getResources().getDrawable(R.drawable.tzone,null);//将来会更改
setImageDrawable(映射[1]);//将在将来更改
//lstZone=findViewById(R.id.lstZone);
//lstZone.setOnItemClickListener(此);
//setAdapter(新的ArrayAdapter(这个,android.R.layout))
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
super.onCreateOptions菜单(菜单);
MenuInflater充气机=getMenuInflater();
充气机。充气(右菜单。右菜单,菜单);
返回true;
}
@凌驾
公共布尔值OnOptionItemSelected(最终菜单项)
{
super.onOptionsItemSelected(项目);
开关(item.getItemId())
{
案例R.id.itemManager:
Toast.makeText(这是“Manager…”,Toast.LENGTH_SHORT.show();
意向管理器=新意向(此,manager.class);
startActivity(经理);
打破
案例R.id.itemLogout:
Toast.makeText(这是“注销…”,Toast.LENGTH_SHORT.show();
完成();
打破
case R.id.itemRating://使其成为对话框而不是活动!
Toast.makeText(这是“开始分级!”,Toast.LENGTH_SHORT.show();
showCustomDialog();
打破
}
返回true;
}
昂佩拉公共空间(视图五)
{
意向peula=新意向(此为PEULOTUCTIVITY.class);
星触觉;
}
私有void showCustomDialog()
{
最终对话框=新对话框(本);
setContentView(R.layout.custom_对话框);
//设置自定义对话框组件-文本、图像和按钮
最终评级条mRatingbar=(评级条)findViewById(R.id.mRatingbar);
最终文本视图tvRatingscale=(文本视图)findViewById(R.id.tvRatingscale);
最终EditText etFeedback=(EditText)findViewById(R.id.etFeedback);
按钮btnSubmit=(按钮)findViewById(R.id.btnSubmit);
mRatingbar.setOnRatingBarChangeListener(新的RatingBar.OnRatingBarChangeListener(){
@凌驾
公共无效率已更改(率条率条、浮点数v、布尔值b){
tvRatingscale.setText(String.valueOf(v));
开关((int)ratingBar.getRating()){
案例1:
tvRatingscale.setText(“非常糟糕”);
打破
案例2:
tvRatingscale.setText(“需要一些改进”);
打破
案例3:
tvRatingscale.setText(“良好”);
打破
案例4:
tvRatingscale.setText(“伟大”);
打破
案例5:
tvRatingscale.setText(“太棒了,我喜欢它”);
打破
违约:
tvRatingscale.setText(“”);
}
}
});
btnSubmit.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
//if(etFeedback.getText().toString().isEmpty()){
//Toast.makeText(ZoneActivity.this,“请填写反馈文本框”,Toast.LENGTH_LONG.show();
//}其他{
etFeedback.setText(“”);
mRatingbar.设定值(0);
//Toast.makeText(ZoneActivity.this,“感谢分享您的反馈”,Toast.LENGTH_SHORT.show();
}
// }
});
dialog.show();
}
@凌驾
公共void onClick(视图v)
{
Toast.makeText(这个“点击”,Toast.LENGTH_SHORT).show();
}
}
我希望当对话框打开时,应用程序不会崩溃,但实际上每次单击打开对话框的按钮时,应用程序都会崩溃

java.lang.InstantiationException:java.lang.Class不能在java.lang.Class.newInstance(本机方法)中实例化。

您需要使用生成器来构造对话框,而不是直接实例化它

对话框类是