我正在使用具有OS Android 5.1.1的Motorola G3设备。
当我尝试从图库中选择一张图片并将其设置为ImageView时,我会遇到异常。以下是我的代码:
<form method='post'>
<input name="username" type="text" placeholder="Username" required="">
<input name="steamid" type="text" placeholder="SteamID64" required="">
<input name="horarytime" type="text" placeholder="Horary Time" required="">
<input name="lua" type="text" placeholder="Do you know about LUA" required="">
<input name="ulx" type="text" placeholder="Do you know about ULX" required="">
<input name="server" type="text" placeholder="If you were admin on another servers, mention them" required="">
<input name="hoursplayed" type="text" placeholder="Paste here your total hours played in the server picture URL" required="">
<input name="warns" type="text" placeholder="Paste here your warns picture URL, !warns IG" required="">
<input name="mic" type="text" placeholder="Do you have a mic?" required="">
<input name="online" type="text" placeholder="How much hours you can play weekly?" required="">
<input name="why" type="text" placeholder="Why do you want to be part of the staff?" required="">
<input name="rank" type="text" placeholder="What rank are you on the server? " required="">
<input name="donated" type="text" placeholder="Did you buyed anything on the server? if so, specify what" required="">
<input name="email" type="text" placeholder="Type EMAIL to be answered" required="">
<input name="age" type="text" placeholder="Type your age" required="">
</div>
<input type="submit" value="SEND APP" name="submit21" />
</form>
<?php
if (isset($_POST['submit21'])) {
echo "<h4>Your apply has been sended successfully, check your mail within 1 day to 7 days to get your answer from the staff team.</h4>";
header("refresh:5;url=../apply/steamauth/logout.php");
$_POST['username'] = $username;
$_POST['steamid'] = $steamid2;
$_POST['horarytime'] = $horarytime;
$_POST['lua'] = $luaknowledge;
$_POST['ulx'] = $ulxknowledge;
$_POST['server'] = $anotherservers;
$_POST['hoursplayed'] = $hoursplayed;
$_POST['warns'] = $warnsurl;
$_POST['mic'] = $hasmic;
$_POST['online'] = $hoursonlineprovided;
$_POST['why'] = $whywantstobefromthestaff;
$_POST['rank'] = $actualrank;
$_POST['donated'] = $hasdonated;
$_POST['age'] = $age;
$_POST['email'] = $mail;
$to = "noreply@vanityrp.site.nfoservers.com";
$subject = "Vanity Roleplay Staff Application";
$message = "
<html>
<head>
<title>Vanity Roleplay Staff Aplication</title>
</head>
<body>
<h3>Username: ".$username."\n \n \n</br></h3>
<h3>SteamID64: ".$steamid2." , transform it to normal SteamID in <link>steamid.io</link>\n \n \n</br></h3>
<h3>Horary Time: ".$horarytime."\n \n \n</br></h3>
<h3>LUA Knowledge: ".$luaknowledge."\n \n \n</br></h3>
<h3>ULX Knowledge: ".$ulxknowledge."\n \n \n</br></h3>
<h3>Servers played as admin: ".$anotherservers."\n \n \n</br></h3>
<h3>Hours Played IG URL: ".$hoursplayed."\n \n \n</br></h3>
<h3>Warns URL: ".$warnsurl."\n \n \n</br></h3>
<h3>Has mic: ".$hasmic."\n \n \n</br></h3>
<h3>Hours online provided: ".$hoursonlineprovided."\n \n \n</br></h3>
<h3>Why wants to be part from the staff team: ".$whywantstobefromthestaff."\n \n \n</br></h3>
<h3>Actual rank: ".$actualrank."\n \n \n</br></h3>
<h3>Has donated: ".$hasdonated."\n \n \n</br></h3>
<h3>Age: ".$age."\n \n \n</br></h3>
<h1><font color='red'>PLEASE BE SURE TO MAIL TO '".$mail."' IF HE DID IT OR NOT!</h1></font>
<h1>THIS IS AN AUTOMATED MESSAGE, PLEASE DO NOT REPLY!</h1>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: noreply@vanityrp.site.nfoservers.com' . "\r\n";
mail($to,$subject,$message,$headers);
}
?>
我调试了代码,并且知道URI正常运行,问题是初始化Bitmap对象。
在这里,我有一个例外:
请有人帮我解决这个问题:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String selectedImageUri = getImageFromChooser(requestCode, resultCode, data);
if (!selectedImageUri.equals("")) {
Uri filePath = data.getData();
try {
Bitmap bitmap = BitmapFactory.decodeFile(selectedImageUri);
ivAvatar.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 120, 120, false));
} catch (Exception e) {
e.printStackTrace();
}
} else {
Toast.makeText(getApplicationContext(), "Try Again!", Toast.LENGTH_LONG).show();
}
}
谢谢!
答案 0 :(得分:4)
它显然写在您的logcat Permission denied
中,您需要在清单中提供READ权限。
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
答案 1 :(得分:2)
您需要在清单文件中提供读取权限。
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />